Update .gitlab-ci.yml
Showing
1 changed file
with
47 additions
and
0 deletions
| 1 | stages: | ||
| 2 | - security | ||
| 3 | - deploy | ||
| 4 | |||
| 5 | secret_grep_scan: | ||
| 6 | stage: security | ||
| 7 | tags: | ||
| 8 | - chatgpt-prod | ||
| 9 | script: | ||
| 10 | - | | ||
| 11 | echo "Scanning for hardcoded AI provider API keys..." | ||
| 12 | PATTERN='(VUE_APP|VITE|REACT_APP|NEXT_PUBLIC|EXPO_PUBLIC|PUBLIC)_[A-Z0-9_]*(KEY|SECRET|TOKEN|PASSWORD|CREDENTIAL)[A-Z0-9_]*[[:space:]]*[:=]|sk-(proj-)?[A-Za-z0-9_-]{20,}|sk-ant-(api03-)?[A-Za-z0-9_-]{20,}|xai-[A-Za-z0-9]{20,}|AIzaSy[A-Za-z0-9_-]{33}|gsk_[A-Za-z0-9]{20,}|pplx-[A-Za-z0-9]{20,}|hf_[A-Za-z0-9]{30,}' | ||
| 13 | grep -Ern "$PATTERN" --exclude-dir=.git --exclude-dir=node_modules --exclude-dir=vendor --exclude-dir=dist --exclude-dir=build --exclude-dir=_srv --include='*.js' --include='*.jsx' --include='*.ts' --include='*.tsx' --include='*.vue' --include='*.php' --include='*.html' --include='*.env' --include='*.env.*' . > raw-matches.txt || true | ||
| 14 | if [ -s raw-matches.txt ]; then | ||
| 15 | echo "🚨 Hardcoded secret pattern(s) detected. Locations below (values redacted):" | ||
| 16 | awk -F: '{print $1":"$2}' raw-matches.txt | sort -u > secret-locations.txt | ||
| 17 | cat secret-locations.txt | ||
| 18 | echo "" | ||
| 19 | echo "File and line number are shown above." | ||
| 20 | echo "Full match details (values redacted) are saved as an artifact." | ||
| 21 | sed -E \ | ||
| 22 | -e 's/(sk-(proj-)?[A-Za-z0-9_-]{6})[A-Za-z0-9_-]+/\1[REDACTED]/g' \ | ||
| 23 | -e 's/(sk-ant-(api03-)?[A-Za-z0-9_-]{6})[A-Za-z0-9_-]+/\1[REDACTED]/g' \ | ||
| 24 | -e 's/(xai-[A-Za-z0-9]{6})[A-Za-z0-9]+/\1[REDACTED]/g' \ | ||
| 25 | -e 's/(AIzaSy[A-Za-z0-9_-]{6})[A-Za-z0-9_-]+/\1[REDACTED]/g' \ | ||
| 26 | -e 's/(gsk_[A-Za-z0-9]{6})[A-Za-z0-9]+/\1[REDACTED]/g' \ | ||
| 27 | -e 's/(pplx-[A-Za-z0-9]{6})[A-Za-z0-9]+/\1[REDACTED]/g' \ | ||
| 28 | -e 's/(hf_[A-Za-z0-9]{6})[A-Za-z0-9]+/\1[REDACTED]/g' \ | ||
| 29 | raw-matches.txt > secret-locations-detail.txt | ||
| 30 | rm -f raw-matches.txt | ||
| 31 | echo "Hardcoded secrets detected. Failing pipeline." | ||
| 32 | exit 1 | ||
| 33 | else | ||
| 34 | echo "No hardcoded secret patterns found." | ||
| 35 | rm -f raw-matches.txt | ||
| 36 | fi | ||
| 37 | artifacts: | ||
| 38 | name: "secret-scan-locations" | ||
| 39 | paths: | ||
| 40 | - secret-locations.txt | ||
| 41 | - secret-locations-detail.txt | ||
| 42 | when: on_failure | ||
| 43 | expire_in: 7 days | ||
| 44 | only: | ||
| 45 | - branches | ||
| 46 | allow_failure: false | ||
| 47 | |||
| 1 | deploy_prod: | 48 | deploy_prod: |
| 2 | stage: deploy | 49 | stage: deploy |
| 3 | script: | 50 | script: | ... | ... |
-
Please register or sign in to post a comment