Skip to content

ci(security): add security-focused CI/CD workflow#2039

Merged
utksh1 merged 2 commits into
utksh1:mainfrom
namann5:ci/security-scan-workflow
Jul 20, 2026
Merged

ci(security): add security-focused CI/CD workflow#2039
utksh1 merged 2 commits into
utksh1:mainfrom
namann5:ci/security-scan-workflow

Conversation

@namann5

@namann5 namann5 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Add a dedicated security CI/CD pipeline that runs on every push/PR to main, preventing regression of the vulnerability classes found in issues #2035 and #2036.

What this workflow checks

Job Purpose
Python Security Linting (Bandit) Static analysis for common Python security anti-patterns (SQL injection, hardcoded passwords, insecure deserialization, etc.). Fails on HIGH severity findings.
Route Authentication Check Scans all APIRouter() definitions in backend/secuscan/ and warns if any lack dependencies=[Depends(require_api_key)] — prevents auth bypass regressions like #2035.
Debug Mode Default Check Verifies debug doesn't default to True and that tracebacks aren't exposed without debug guards — prevents info disclosure regressions like #2036.
Hardcoded Secret Detection Pattern-matches for hardcoded passwords, API keys, tokens, and default DB credentials across Python and Docker Compose files.
Environment Config Validation Validates .env.example has safe defaults (debug=false, no placeholder secrets).
Dependency Security Audit Runs pip-audit against backend/requirements.txt to catch known CVEs in dependencies.

Why this matters

The two critical vulnerabilities found (#2035 auth bypass, #2036 debug exposure) were both configuration-level issues that could easily be reintroduced. This workflow provides automated regression prevention for:

  • Authentication coverage gaps
  • Insecure default configurations
  • Hardcoded credentials
  • Known dependency vulnerabilities

Labels

type:devops, level:advanced, priority:high

Add a dedicated security CI/CD pipeline that runs on push/PR to main.
Catches the classes of vulnerabilities identified in issues utksh1#2035 and utksh1#2036:

- Bandit Python security linting (high-severity gate)
- Route authentication protection checks
- Debug mode default validation
- Hardcoded secret detection
- Environment configuration validation
- Dependency vulnerability auditing

This provides continuous security regression testing to prevent
similar vulnerabilities from being introduced in future PRs.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 817de28d4f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/security-ci.yml Outdated
if re.search(r'debug\s*[=:]\s*True', line) and 'if' not in line and '#' not in line.split('debug')[0]:
issues.append(f'{py_file}:{i}: debug defaults to True')
# Check for traceback.format_exc in responses
if 'traceback.format_exc' in line and 'settings.debug' not in content.split(line)[max(0, content.split(line)[0].rfind('if')):]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fix the debug guard check that fails safe handlers

In the current tree the exception handler in backend/secuscan/main.py has if settings.debug: immediately above traceback.format_exc(), but this expression slices the list returned by content.split(line) instead of checking the nearby source text, so it evaluates as if the guard is missing and exits 1 on every run. This makes the new workflow fail even for tracebacks that are correctly guarded by debug mode.

Useful? React with 👍 / 👎.

Comment thread .github/workflows/security-ci.yml Outdated

# Patterns that indicate hardcoded secrets
patterns = [
(r'password\s*=\s*[\"'][^\"']+[\"']', 'Hardcoded password'),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fix secret scan regex strings that fail to parse

When this workflow reaches secret-scan, Python parses this raw single-quoted regex and the unescaped ' inside [\"'] closes the string, so the inline script raises a SyntaxError before scanning. The same quoting pattern is repeated on the following regexes, which makes the new security job fail on every push/PR rather than reporting hardcoded secrets.

Useful? React with 👍 / 👎.

Fix two issues flagged by the bot review:

1. Debug guard check: The original logic used content.split(line) which
   incorrectly sliced strings. Replace with proper backward scan that
   checks the 10 lines above traceback.format_exc for an
   if-settings.debug guard.

2. Secret scan regex: Replace character class quoting with hex-escaped
   patterns to avoid YAML/Python shell quoting conflicts that caused
   SyntaxError. Also simplify the POSTGRES_PASSWORD pattern.

All f-string interpolations replaced with .format() to avoid nested
quote escaping issues in YAML run blocks.
@utksh1

utksh1 commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Rebased with main to pick up the TLS test fixes from #2040 and #2041. The test failures should be resolved now. Let's see if the Bandit HIGH severity findings are from existing code or need addressing.

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent security CI workflow! This adds automated regression prevention for auth bypass, debug exposure, hardcoded secrets, and dependency vulnerabilities.

The Bandit HIGH severity findings (SHA1 usage in finding_intelligence.py:75 and platform_resources.py:29) are pre-existing issues in main, not introduced by this PR. These should be fixed by adding usedforsecurity=False parameter since they're used for ID generation, not cryptographic security.

The backend-unit test failures were already fixed by #2040 and #2041. Once CI re-runs on the updated branch, those should pass.

Merging this workflow so we have automated security checks going forward. The SHA1 findings can be addressed in a follow-up PR.

@utksh1
utksh1 merged commit 11d70b2 into utksh1:main Jul 20, 2026
22 of 24 checks passed
@utksh1 utksh1 added type:devops DevOps or infrastructure work category bonus label type:security Security work category bonus label area:backend Backend API, database, or service work level:advanced 55 pts difficulty label for advanced contributor PRs gssoc:approved Admin validation: approved for GSSoC scoring labels Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend Backend API, database, or service work gssoc:approved Admin validation: approved for GSSoC scoring level:advanced 55 pts difficulty label for advanced contributor PRs type:devops DevOps or infrastructure work category bonus label type:security Security work category bonus label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants