fix: validate KEY against allowlist in read_config.sh#39
Open
xiaolai wants to merge 1 commit intoagenticnotetaking:mainfrom
Open
fix: validate KEY against allowlist in read_config.sh#39xiaolai wants to merge 1 commit intoagenticnotetaking:mainfrom
xiaolai wants to merge 1 commit intoagenticnotetaking:mainfrom
Conversation
KEY was interpolated directly into grep -E as a regex pattern without
validation. Callers currently only pass literal strings ("git",
"session_capture"), but any future caller passing untrusted input could
trigger unexpected regex matches. An allowlist ensures only known keys
can be queried, making the safe path the only path.
Co-Authored-By: Claude Code <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security Fix (MEDIUM)
File:
hooks/scripts/read_config.sh:30The
KEYargument was interpolated directly into agrep -Eregex pattern without validation:VALUE=$(grep -E "^${KEY}:" "$CONFIG_FILE" ...)Special regex characters in
KEYcould cause unexpected matches (e.g.,KEY=".+"would match every line). While the current callers (session-orient.shandauto-commit.sh) always pass literal strings ("git","session_capture"), any future caller passing user-influenced input could trigger unintended behaviour.Fix
Added a
caseallowlist before the grep call. Only the two known valid keys (git,session_capture) pass through; anything else returns the default value immediately. This is a safe, backward-compatible hardening — existing behaviour is identical for all current callers.The allowlist documents the intended API of the function and makes the safe path the only path. Adding new config keys in the future requires an explicit allowlist update, which is the right forcing function.
Files changed
hooks/scripts/read_config.sh