T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/security-audit.sh:248
- Finding
- Secret Detection Results Can Expose Credentials in Terminal and CI Logs<![CDATA[ ## Vulnerability Details **File Location**: `scripts/security-audit.sh:248-255`; related instances in `SKILL.md:452-458`, `templates/security-audit.yml:48-64`, and `templates/security-audit.gitlab-ci.yml:24-30` **Vulnerability Type**: Sensitive information exposure through diagnostic output **Risk Level**: High ### Vulnerable Code ```bash local matches=$(grep -rn "$pattern" \ --include='*.ts' --include='*.js' --include='*.py' --include='*.go' \ --include='*.env' --include='*.yml' --include='*.yaml' --include='*.json' \ "$PROJECT_DIR" 2>/dev/null | grep -v "node_modules\|.git\|test\|spec\|example\|placeholder\|your_\|YOUR_\|xxxx\|XXXX" | head -5) if [ -n "$matches" ]; then error "Found potential $name" if [ "$VERBOSE" = true ]; then echo "$matches" | head -3 fi ``` The CI templates similarly invoke `grep` without suppressing matched lines: ```yaml - name: Secret Detection run: | # AWS Access Keys ! grep -rn 'AKIA[0-9A-Z]\{16\}' --include='*.{js,ts,py,env,yml,yaml}' . # OpenAI API Keys ! grep -rn 'sk-[A-Za-z0-9]\{20,\}' --include='*.{js,ts,py,env}' . # GitHub Tokens ! grep -rn 'ghp_[A-Za-z0-9]\{36\}\|github_pat_' --include='*.*' . # Private Keys ! grep -rn 'BEGIN.*PRIVATE KEY' --include='*.*' . continue-on-error: true ``` ### Technical Analysis The scanner stores complete matching source lines in `matches` and prints up to three of those lines when verbose mode is enabled. Because secret assignments commonly place the credential and variable name on the same line, this output can disclose the complete credential. The CI checks also use ordinary recursive `grep`, which prints matching file names, line numbers, and line contents. Negating the exit status with `!` changes only success or failure; it does not suppress output. Consequently, detected secrets may be copied from source files into CI logs. CI logs can have different retention policies and broader access than repositor ...[truncated 1313 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Never print complete matching lines for secret findings. 2. Report only the secret type, relative file path, line number, and a redacted fingerprint. 3. Replace CI checks that only require a Boolean result with quiet matching: ```bash if grep -qrn 'AKIA[0-9A-Z]\{16\}' --include='*.{js,ts,py,env,yml,yaml}' .; then echo "Potential AWS access key detected; inspect the secure scanner report." exit 1 fi ``` 4. If diagnostic context is required, redact the matched value before output and reveal no more than a few non-sensitive prefix or suffix characters. 5. Configure CI masking and restrict log visibility and retention. 6. Store detailed findings in an encrypted, access-controlled artifact rather than ordinary build logs. 7. Add automated tests confirming that known test credentials never appear verbatim in scanner output. ]]>
