Skip to content

feat: auth_format parameter for Level 2 authenticated scanning + report dir fix#4

Open
jordi-murgo wants to merge 2 commits into
BugTraceAI:mainfrom
jordi-murgo:feat/auth-level2-format
Open

feat: auth_format parameter for Level 2 authenticated scanning + report dir fix#4
jordi-murgo wants to merge 2 commits into
BugTraceAI:mainfrom
jordi-murgo:feat/auth-level2-format

Conversation

@jordi-murgo
Copy link
Copy Markdown

Summary

Two fixes for authenticated scanning and report lookups:

1. auth_format parameter for Level 2 login (feat)

Level 2 authentication now supports an explicit auth_format parameter to control how login credentials are sent:

  • "json" (default): sends credentials as JSON body via POST — works with REST APIs (e.g. Juice Shop /rest/user/login)
  • "form": extracts CSRF tokens from the login page HTML, then sends credentials as application/x-www-form-urlencoded via POST — works with traditional web apps (e.g. DVWA /login.php)

Files changed:

  • scan_service.py: _setup_auth_tokens uses auth_format to choose json= vs data=, captures both JWT tokens and session cookies via client.cookies
  • gospider_agent.py: accepts scan_ctx_id, retrieves auth headers (cookies + JWT) from scan context, passes --cookie and `-H Authorization to GoSpider
  • team.py: passes scan_context to GoSpiderAgent constructor
  • external.py: run_gospider accepts extra_headers, passes them as -H flags to GoSpider CLI
  • scan_context.py: added auth_format field to ScanOptions
  • api/routes/scans.py: passes auth_format from request to ScanOptions
  • api/schemas.py: added auth_format field to CreateScanRequest

Fixes: GoSpider was starting authenticated sessions via Level 2 but cookies/JWT tokens were never forwarded to the crawler, making authenticated crawling ineffective.

Tested end-to-end:

  • DVWA (auth_format="form"): 2 session cookies captured, CSRF token auto-extracted, GoSpider finds 5+ authenticated URLs
  • Juice Shop (auth_format="json"): JWT extracted from login response, passed as Authorization: Bearer header to GoSpider

2. Report directory lookup fix (fix)

When a scan has no target record in the database (e.g. deleted or orphaned), _find_report_dir would bail out early. Now falls through to a filesystem scan that matches report directories by scan_id in their validated_findings.json or raw_findings.json metadata.

Files changed:

  • reports.py: handle missing scan/target gracefully, add filesystem fallback scanning all report dirs for scan_id

Related: #3 (GoSpider auth headers issue)

Jordi added 2 commits May 22, 2026 10:48
When a scan has no target record in the database (e.g. deleted or
orphaned), _find_report_dir would bail out early. Now falls through
to a filesystem scan that matches report directories by scan_id
in their validated_findings.json or raw_findings.json metadata.

- Handle missing scan/target gracefully (was returning None)
- Add filesystem fallback scanning all report dirs for scan_id
- Check validated_findings.json and raw_findings.json for metadata match
Level 2 authentication now supports explicit auth_format to control
how login credentials are sent:

- "json" (default): sends credentials as JSON body via POST
  Works with REST APIs (e.g. Juice Shop /rest/user/login)
- "form": extracts CSRF tokens from login page HTML, then sends
  credentials as application/x-www-form-urlencoded via POST
  Works with traditional web apps (e.g. DVWA /login.php)

Changes:
- scan_service.py: _setup_auth_tokens now accepts auth_format from
  ScanOptions, uses json= or data= accordingly, captures both JWT
  tokens and session cookies via client.cookies jar
- gospider_agent.py: accepts scan_ctx_id, retrieves auth headers
  (cookies + JWT) from scan context, passes --cookie and -H
  Authorization to GoSpider
- team.py: passes scan_context to GoSpiderAgent constructor
- external.py: run_gospider accepts extra_headers, passes them as
  -H flags to the GoSpider CLI
- scan_context.py: added auth_format field to ScanOptions
- api/routes/scans.py: passes auth_format from request to ScanOptions
- api/schemas.py: added auth_format field to CreateScanRequest

Fixes authentication bypass in GoSpider where Level 2 sessions were
started but cookies/JWT tokens were never forwarded to the crawler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant