-
Notifications
You must be signed in to change notification settings - Fork 32
fix(security): replace hardcoded S3 credentials with environment vari… #99
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| <?php | ||
|
|
||
| $files = [ | ||
| 'common/config/main.php', | ||
| 'environments/prod-railway/common/config/main-local.php' | ||
| ]; | ||
|
|
||
| $patterns = [ | ||
| 'AKIAWMITDJRKVN5ODY2X', | ||
| 'zAr8Xov1olqBAaiE8CX+j45qDHaAbO+S3EhUVeaT', | ||
| 'AKIAWMITDJRKWZZEWCUM', | ||
| 'M6olF9l1pZ1sKIswrSCjKtGkAG2w9qDV9x230UlI' | ||
| ]; | ||
|
|
||
| $envVars = [ | ||
| 'AWS_TEMP_BUCKET_KEY', | ||
| 'AWS_TEMP_BUCKET_SECRET', | ||
| 'AWS_PERMANENT_S3_ACCESS_KEY_ID', | ||
| 'AWS_PERMANENT_S3_SECRET_ACCESS_KEY' | ||
| ]; | ||
|
|
||
| $errors = []; | ||
|
|
||
| foreach ($files as $file) { | ||
| $content = file_get_contents($file); | ||
| if ($content === false) { | ||
| $errors[] = "Could not read file: $file"; | ||
| continue; | ||
| } | ||
|
|
||
| foreach ($patterns as $pattern) { | ||
| if (strpos($content, $pattern) !== false) { | ||
| $errors[] = "Found hardcoded credential '$pattern' in $file"; | ||
| } | ||
| } | ||
|
|
||
| foreach ($envVars as $envVar) { | ||
| if (strpos($content, "getenv('$envVar')") === false) { | ||
| // Check if it's the right file for the env var | ||
| if ($file === 'common/config/main.php' && (strpos($envVar, 'TEMP') !== false)) { | ||
| $errors[] = "Missing getenv('$envVar') in $file"; | ||
| } | ||
| if ($file === 'environments/prod-railway/common/config/main-local.php' && (strpos($envVar, 'PERMANENT') !== false)) { | ||
| $errors[] = "Missing getenv('$envVar') in $file"; | ||
| } | ||
|
Comment on lines
+37
to
+45
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. Make getenv checks syntax-tolerant and file-explicit. The current check only matches the exact text Suggested hardening-$envVars = [
- 'AWS_TEMP_BUCKET_KEY',
- 'AWS_TEMP_BUCKET_SECRET',
- 'AWS_PERMANENT_S3_ACCESS_KEY_ID',
- 'AWS_PERMANENT_S3_SECRET_ACCESS_KEY'
-];
+$expectedEnvVarsByFile = [
+ 'common/config/main.php' => [
+ 'AWS_TEMP_BUCKET_KEY',
+ 'AWS_TEMP_BUCKET_SECRET',
+ ],
+ 'environments/prod-railway/common/config/main-local.php' => [
+ 'AWS_PERMANENT_S3_ACCESS_KEY_ID',
+ 'AWS_PERMANENT_S3_SECRET_ACCESS_KEY',
+ ],
+];
@@
- foreach ($envVars as $envVar) {
- if (strpos($content, "getenv('$envVar')") === false) {
- // Check if it's the right file for the env var
- if ($file === 'common/config/main.php' && (strpos($envVar, 'TEMP') !== false)) {
- $errors[] = "Missing getenv('$envVar') in $file";
- }
- if ($file === 'environments/prod-railway/common/config/main-local.php' && (strpos($envVar, 'PERMANENT') !== false)) {
- $errors[] = "Missing getenv('$envVar') in $file";
- }
- }
- }
+ foreach ($expectedEnvVarsByFile[$file] as $envVar) {
+ $pattern = '/getenv\(\s*[\'"]' . preg_quote($envVar, '/') . '[\'"]\s*\)/';
+ if (!preg_match($pattern, $content)) {
+ $errors[] = "Missing getenv(...) for $envVar in $file";
+ }
+ }🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| } | ||
|
|
||
| if (empty($errors)) { | ||
| echo "Verification PASSED: No hardcoded credentials found and environment variables are used.\n"; | ||
| exit(0); | ||
| } else { | ||
| echo "Verification FAILED:\n"; | ||
| foreach ($errors as $error) { | ||
| echo "- $error\n"; | ||
| } | ||
| exit(1); | ||
| } | ||
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.
Remove real credential literals from the verifier.
Line 9 through Line 12 stores full AWS credential values in source, which reintroduces secret exposure and is already tripping GitGuardian in this PR.
🧰 Tools
🪛 GitHub Check: GitGuardian Security Checks
[error] 10-10: GitGuardian detected hardcoded AWS IAM Keys (AWS secret) in this file. GitGuardian status: Triggered (incident 23895785).
[error] 12-12: GitGuardian detected hardcoded AWS IAM Keys (AWS secret) in this file. GitGuardian status: Triggered (incident 23895792).
🤖 Prompt for AI Agents