-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix claude code entrypoint leak #1165
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 | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -132,6 +132,18 @@ export function formatLeakError( | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const consent = consentCopy(context); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Collect all unique keys from findings | ||||||||||||||||||||||||||||||||||||||||||||
| const allKeys = new Set<string>(); | ||||||||||||||||||||||||||||||||||||||||||||
| report.findings.forEach(finding => { | ||||||||||||||||||||||||||||||||||||||||||||
| finding.keys.forEach(key => allKeys.add(key)); | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| const keysArray = Array.from(allKeys); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Generate grep command that excludes all detected keys | ||||||||||||||||||||||||||||||||||||||||||||
| const grepCommand = keysArray | ||||||||||||||||||||||||||||||||||||||||||||
| .map(key => `grep -v '^${key}='`) | ||||||||||||||||||||||||||||||||||||||||||||
| .join(' | ') + ' .env > .env.tmp && mv .env.tmp .env'; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+135
to
+146
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. Fix generated remediation command for multiple keys. Line 143-145 builds an invalid pipeline for >1 key (only the last 💡 Proposed fix- // Collect all unique keys from findings
- const allKeys = new Set<string>();
- report.findings.forEach(finding => {
- finding.keys.forEach(key => allKeys.add(key));
- });
- const keysArray = Array.from(allKeys);
-
- // Generate grep command that excludes all detected keys
- const grepCommand = keysArray
- .map(key => `grep -v '^${key}='`)
- .join(' | ') + ' .env > .env.tmp && mv .env.tmp .env';
+ // Collect unique concrete env var keys only (skip diagnostic placeholders)
+ const keysArray = Array.from(new Set(report.findings.flatMap(f => f.keys))).filter(key =>
+ /^[A-Z_][A-Z0-9_]*$/.test(key)
+ );
+
+ const escapedKeys = keysArray.map(key => key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
+ const grepCommand =
+ escapedKeys.length > 0
+ ? `grep -v -E '^(${escapedKeys.join('|')})=' .env > .env.tmp && mv .env.tmp .env`
+ : '# No concrete key names could be derived; remove keys manually from .env';📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| return `${header} | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Found: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -145,7 +157,7 @@ ${fileList} | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Choose one: | ||||||||||||||||||||||||||||||||||||||||||||
| 1. Remove the key from this repo's .env (recommended): | ||||||||||||||||||||||||||||||||||||||||||||
| grep -v '^ANTHROPIC_API_KEY=' .env > .env.tmp && mv .env.tmp .env | ||||||||||||||||||||||||||||||||||||||||||||
| ${grepCommand} | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| 2. Rename to a non-auto-loaded file: | ||||||||||||||||||||||||||||||||||||||||||||
| mv .env .env.secrets | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
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.
When more than one sensitive key is detected, this formatter emits a command like
grep -v '^KEY1=' | grep -v '^KEY2=' .env > .env.tmp ...; in that form, the firstgrephas no file/stdin source and waits on terminal input, so the recommended remediation hangs instead of editing.env. This only appears in multi-key findings (for example.envcontaining bothOPENAI_API_KEYandGEMINI_API_KEY), which is a common case for this gate.Useful? React with 👍 / 👎.