Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

ci(nuclei): authenticate DAST scan + seed URLs from Flask url_map (#3698)

LearningCircuit903a2db8af7f
diff --git a/.github/workflows/nuclei.yml b/.github/workflows/nuclei.yml
index 85d12f6ded..139fd3ded1 100644
--- a/.github/workflows/nuclei.yml
+++ b/.github/workflows/nuclei.yml
@@ -1,8 +1,14 @@
name: Nuclei Vulnerability Scan
-# Template-driven DAST scanner - complements ZAP with known-CVE checks,
-# misconfiguration detection, exposed panel discovery, and default credential testing.
-# Uses ProjectDiscovery's 6,500+ community-maintained templates.
+# Template-driven DAST scanner — complements ZAP with known-CVE checks,
+# misconfiguration detection, exposed panel discovery, and default credential
+# testing. Uses ProjectDiscovery's 6,500+ community-maintained templates.
+#
+# Authenticated scan: the runner pre-creates the standard CI test_admin user,
+# logs in via the real /auth/login flow to capture a session cookie, and
+# seeds Nuclei with the full Flask url_map so the scanner probes the entire
+# authenticated app surface (settings, research, history, API, …) — not just
+# the unauthenticated landing page.
on:
workflow_call: # Called by release-gate.yml
@@ -20,6 +26,17 @@ jobs:
security-events: write
actions: read
+ env:
+ CI: true
+ TEST_ENV: true
+ FLASK_ENV: testing
+ LDR_DATA_DIR: ${{ github.workspace }}/data
+ LDR_DB_KDF_ITERATIONS: "1000"
+ DISABLE_RATE_LIMITING: "true"
+ SECRET_KEY: test-secret-key-for-ci
+ TEST_USERNAME: test_admin
+ TEST_PASSWORD: testpass123
+
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
@@ -50,10 +67,19 @@ jobs:
run: |
pdm sync -d
+ - name: Setup test data directory
+ run: |
+ mkdir -p "$LDR_DATA_DIR/encrypted_databases"
+
+ - name: Pre-create CI test user
+ # Avoids the slow registration path (KDF + 500 settings rows) and
+ # avoids hitting the registration rate limit during the scan window.
+ run: |
+ export PYTHONPATH=$PWD/src:$PYTHONPATH
+ pdm run python scripts/ci/init_test_database.py
+
- name: Start LDR server for testing
run: |
- export CI=true
- export LDR_DB_KDF_ITERATIONS=1000
export PYTHONPATH=$PWD/src:$PYTHONPATH
pdm run python -m local_deep_research.web.app > server.log 2>&1 &
SERVER_PID=$!
@@ -63,7 +89,7 @@ jobs:
# --connect-timeout/--max-time bound TCP and total request time so a
# hung connection fails fast instead of eating the job timeout.
for _ in {1..90}; do
- if curl -s --connect-timeout 2 --max-time 5 http://localhost:5000/api/v1/health > /dev/null; then
+ if curl -s --connect-timeout 2 --max-time 5 http://127.0.0.1:5000/api/v1/health > /dev/null; then
echo "Server started successfully"
break
fi
@@ -71,12 +97,84 @@ jobs:
done
# Verify server is running
- if ! curl -s --connect-timeout 2 --max-time 5 http://localhost:5000/api/v1/health > /dev/null; then
+ if ! curl -s --connect-timeout 2 --max-time 5 http://127.0.0.1:5000/api/v1/health > /dev/null; then
echo "Server failed to start"
cat server.log
exit 1
fi
+ - name: Dump Flask url_map for URL seeding
+ # Without -list, Nuclei only probes the single -target URL. Seeding
+ # with the real url_map lets it exercise every blueprint route.
+ run: |
+ export PYTHONPATH=$PWD/src:$PYTHONPATH
+ pdm run python scripts/ci/dump_url_map.py http://127.0.0.1:5000 > urls.txt
+ echo "Seeded $(wc -l < urls.txt) URLs:"
+ head -20 urls.txt
+ echo "..."
+
+ - name: Authenticate and capture session cookie
+ id: login
+ run: |
+ # Step 1: GET /auth/login → establishes a Flask session cookie and
+ # returns the HTML form with the per-session CSRF token.
+ curl -sS -c cookies.txt -o login.html http://127.0.0.1:5000/auth/login
+
+ CSRF=$(grep -oE 'name="csrf_token"[[:space:]]+value="[^"]+"' login.html \
+ | head -n1 \
+ | sed -E 's/.*value="([^"]+)".*/\1/')
+ if [ -z "$CSRF" ]; then
+ echo "Failed to extract CSRF token from login page"
+ head -200 login.html
+ exit 1
+ fi
+
+ # Step 2: POST credentials with the CSRF token and the cookie jar.
+ # -L follows the post-login 302 to /. -o /dev/null discards body,
+ # -w prints the final HTTP code so a non-2xx fails the step.
+ HTTP_CODE=$(curl -sS -L \
+ -b cookies.txt -c cookies.txt \
+ -o /dev/null -w '%{http_code}' \
+ --data-urlencode "username=${TEST_USERNAME}" \
+ --data-urlencode "password=${TEST_PASSWORD}" \
+ --data-urlencode "csrf_token=${CSRF}" \
+ http://127.0.0.1:5000/auth/login)
+ if [ "$HTTP_CODE" != "200" ]; then
+ echo "Login failed with HTTP $HTTP_CODE"
+ cat server.log
+ exit 1
+ fi
+
+ # Verify the session is actually authenticated (not just that
+ # the login page rendered with a 200 from a re-display of errors).
+ AUTHED=$(curl -sS -b cookies.txt http://127.0.0.1:5000/auth/check)
+ echo "auth/check response: $AUTHED"
+ echo "$AUTHED" | grep -q '"authenticated":[[:space:]]*true' || {
+ echo "Authenticated check failed"
+ exit 1
+ }
+
+ # Extract the session cookie value from the Netscape cookie jar.
+ # Format: domain TAB tailmatch TAB path TAB secure TAB expires TAB name TAB value
+ SESSION=$(awk '$6 == "session" { print $7 }' cookies.txt | tail -n1)
+ if [ -z "$SESSION" ]; then
+ # Print every column EXCEPT the value ($7) so we can debug
+ # without leaking the cookie if the awk filter is broken.
+ echo "Could not find 'session' cookie in jar (values redacted):"
+ awk '{ print $1, $2, $3, $4, $5, $6 }' cookies.txt
+ exit 1
+ fi
+ # Mask the cookie in logs — it grants full app access for this run.
+ echo "::add-mask::$SESSION"
+ echo "session=$SESSION" >> "$GITHUB_OUTPUT"
+
+ # Give the post-login background thread a moment to finish
+ # the settings-migration / library-init pass it kicks off
+ # (see _perform_post_login_tasks in web/auth/routes.py).
+ # Otherwise the first authenticated probes can race those
+ # writes and 500 on settings-dependent routes.
+ sleep 2
+
- name: Create empty SARIF fallback
run: |
cat > nuclei.sarif << 'SARIF'
@@ -99,11 +197,26 @@ jobs:
- name: Run Nuclei scan
uses: projectdiscovery/nuclei-action@cc153d0541e1adf8a42bbe31c0a4fb2376147538 # v3.1.1
with:
- # Exclude http-missing-security-headers: all recommended headers are
- # already set (see security/security_headers.py). The alert fires
- # because HSTS is correctly omitted on plain HTTP (localhost) and
- # X-XSS-Protection is intentionally omitted (deprecated, replaced by CSP).
- args: -target http://localhost:5000 -eid http-missing-security-headers -sarif-export nuclei.sarif -output nuclei.log
+ # -list: probe every route in the Flask url_map (not just /).
+ # -H: attach the authenticated session cookie so probes hit the
+ # real app surface, not the login redirect.
+ # -severity: drop info-level noise (form-detection, options-method,
+ # intentional CSP/cookie choices). Real findings are >= low.
+ # -etags intrusive,dos,fuzz: with a live session, default templates
+ # can mutate state or DoS the runner. Exclude the standard
+ # destructive tag set for authenticated DAST.
+ # -eid http-missing-security-headers: HSTS is correctly omitted on
+ # plain HTTP localhost; X-XSS-Protection is intentionally
+ # omitted (deprecated, replaced by CSP). See
+ # security/security_headers.py.
+ args: >-
+ -list urls.txt
+ -H "Cookie: session=${{ steps.login.outputs.session }}"
+ -severity low,medium,high,critical
+ -etags intrusive,dos,fuzz
+ -eid http-missing-security-headers
+ -sarif-export nuclei.sarif
+ -output nuclei.log
- name: Upload Nuclei SARIF to GitHub Security tab
uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
@@ -120,6 +233,8 @@ jobs:
path: |
nuclei.log
nuclei.sarif
+ urls.txt
+ server.log
retention-days: 30
- name: Stop server
diff --git a/scripts/ci/dump_url_map.py b/scripts/ci/dump_url_map.py
new file mode 100755
index 0000000000..3ca877e210
--- /dev/null
+++ b/scripts/ci/dump_url_map.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+"""
+Dump the Flask url_map to a file as one absolute URL per line.
+
+Used by the Nuclei DAST workflow to seed a URL list so the scanner
+probes the actual application surface (authenticated routes, API
+endpoints, blueprints) instead of just the index page.
+
+Parameterized routes (`/research/<string:research_id>/status`) are
+emitted with a converter-appropriate placeholder so Nuclei still
+exercises the path. The substituted URL will usually 404 (the resource
+doesn't exist for the test user), but that is fine — Nuclei probes path
+traversal, parameter injection, and SQLi templates against the URL
+pattern, not against a specific resource.
+
+Skips:
+ - The Flask `static` endpoint (asset serving, no app logic).
+ - Routes that don't accept GET — Nuclei templates almost exclusively
+ issue GET probes, so POST-only endpoints just generate 405s.
+
+Usage:
+ python scripts/ci/dump_url_map.py http://127.0.0.1:5000 > urls.txt
+"""
+
+import re
+import sys
+
+
+# Map Flask URL converters to a placeholder that satisfies the converter
+# so Flask routes the request to the handler instead of 404-ing at the
+# converter stage. Anything not listed falls back to a plain string.
+_PLACEHOLDERS = {
+ "int": "1",
+ "float": "1",
+ "uuid": "00000000-0000-0000-0000-000000000000",
+}
+_DEFAULT_PLACEHOLDER = "nuclei"
+
+_PARAM_RE = re.compile(
+ r"<(?:(?P<conv>[a-zA-Z_][a-zA-Z0-9_]*)(?:\([^)]*\))?:)?(?P<name>[a-zA-Z_][a-zA-Z0-9_]*)>"
+)
+
+
+def _substitute(match: "re.Match[str]") -> str:
+ return _PLACEHOLDERS.get(match.group("conv") or "", _DEFAULT_PLACEHOLDER)
+
+
+def main() -> int:
+ if len(sys.argv) != 2:
+ print(f"Usage: {sys.argv[0]} BASE_URL", file=sys.stderr)
+ return 2
+
+ base_url = sys.argv[1].rstrip("/")
+
+ from local_deep_research.web.app_factory import create_app
+
+ app, _ = create_app()
+
+ seen: set[str] = set()
+ for rule in app.url_map.iter_rules():
+ if rule.endpoint == "static":
+ continue
+ if "GET" not in (rule.methods or set()):
+ continue
+ path = _PARAM_RE.sub(_substitute, rule.rule)
+ url = f"{base_url}{path}"
+ if url in seen:
+ continue
+ seen.add(url)
+ print(url)
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())