-
-
Notifications
You must be signed in to change notification settings - Fork 272
Load secrets from _FILE environment variables #2019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,4 +34,16 @@ fi | |
| mkdir -p /app/data /bookdrop /books | ||
| chown "$USER_ID:$GROUP_ID" /app/data /bookdrop /books 2>/dev/null || true | ||
|
|
||
| # Process _FILE environment variables for secrets | ||
| for var in $(env | grep '_FILE=' | cut -d= -f1); do | ||
| file_path=$(eval echo \$$var) | ||
| if [ -n "$file_path" ] && [ -f "$file_path" ]; then | ||
| var_name=${var%_FILE} | ||
| export "$var_name"=$(cat "$file_path") | ||
|
Comment on lines
+38
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Restrict discovery to variable names ending in The 🧰 Tools🪛 ast-grep (0.44.1)[error] 38-38: (eval-on-variable-bash) 🪛 Shellcheck (0.11.0)[info] 39-39: Double quote to prevent globbing and word splitting. (SC2086) [warning] 42-42: Quote this to prevent word splitting. (SC2046) 🤖 Prompt for AI Agents |
||
| echo "✓ Loaded $var_name from $file_path" | ||
| elif [ -n "$file_path" ]; then | ||
| echo "⚠ Warning: File $file_path not found for $var" | ||
| fi | ||
| done | ||
|
|
||
| exec su-exec "$USER_ID:$GROUP_ID" "$@" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🔴 Critical | ⚡ Quick win
Remove
evalfrom environment-variable lookup.eval echo \$$varreparses the environment-derived name as shell code. A crafted environment variable name can therefore execute arbitrary commands beforesu-execdrops privileges. Use a safe lookup such asprintenv "$var"and validate the variable name before exporting it.🧰 Tools
🪛 ast-grep (0.44.1)
[error] 38-38:
evalis invoked on a variable, parameter expansion, or command-substitution result, which re-parses the value as shell code. If any part of that value is attacker-controlled (arguments, environment, file contents, network output), it allows arbitrary command execution. Do notevaldynamic data: invoke the command directly with proper quoting (e.g."$cmd" "$arg"), use arrays for argument lists (cmd=(prog --flag "$value"); "${cmd[@]}"), or restrict input to a validated allowlist before running it.Context: eval echo $$var
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(eval-on-variable-bash)
🪛 Shellcheck (0.11.0)
[info] 39-39: Double quote to prevent globbing and word splitting.
(SC2086)
🤖 Prompt for AI Agents
Source: Linters/SAST tools