Skip to content

feat(sensor): attribute runtime hits to live traffic route templates and auth state (#69) - #228

Open
SriRamkunamsetty wants to merge 1 commit into
secfoo-com:mainfrom
SriRamkunamsetty:feat/route-auth-attribution-69
Open

SriRamkunamsetty wants to merge 1 commit into
secfoo-com:mainfrom
SriRamkunamsetty:feat/route-auth-attribution-69

Conversation

@SriRamkunamsetty

Copy link
Copy Markdown
Contributor

Fixes #69

Summary

Adds live request, job, and auth state attribution for Python and Node.js probes while enforcing the privacy guarantee (route templates only — never concrete paths, query strings, header/cookie values, tokens, or user IDs):

  • Python (\contextvars.ContextVar, \src/secfoo/sensor/context.py\ & \probe.py):

    • Automatic zero-code framework hooks (when \SECFOO_SENSOR=1) + explicit middlewares (\SecfooASGIMiddleware\ for FastAPI/Starlette, \SecfooWSGIMiddleware\ / \install_flask\ for Flask, \SecfooDjangoMiddleware\ for Django), normalizing int:id patterns cleanly to {id}\ and defaulting unmatched routes to \unknown.
    • \job_context(name)\ helper for \job:\ background execution tagging.
    • \detect_auth_state()\ checking framework auth posture (\is_authenticated) and header/session cookie presence (never reading values).
    • Keyed hits by (fingerprint, symbol, route, auth)\ and counted per-route requests on sessions (
      outes_seen).
  • Node.js (\AsyncLocalStorage,
    pm/secfoo-sensor/):

    • \expressMiddleware()\ reading
      eq.baseUrl + req.route.path\ and \ astifyPlugin\ reading
      equest.routeOptions.url\ /
      outerPath.

    • unWithJob, \NodeHitCollector, template sanitization, and
      ode --test\ suite validated directly against \secfoo.runtime.evidence.validate_event.
  • Contract & Dashboard Integration:

    • Extended \evidence.schema.json,
      untime/evidence.py, \schema.sql,
      epository.py, and \web/sca_runtime.py\ with validated
      outes_seen\ storage and
      eached on X of Y routes seen\ summaries.

Benchmark & Verification

  • Node HTTP server (1,000 reqs): \1,818 rps\ bare vs \1,857 rps\ probed (-2.14%\ throughput loss, -0.61 ms\ p99 delta).
  • Python FastAPI (1,500 reqs) & Conformance Kit: \167.4 rps\ bare vs \184.3 rps\ probed; watched-call marginal overhead +0.84 us/call\ (budget \50 us), \6/6\ conformance checks passed.
  • Checks:
    uff check .\ clean, \�andit -c .bandit -ll -r src/secfoo\ clean, \pytest tests/test_sensor/ tests/test_runtime/ tests/test_web/test_sca_runtime.py tests/test_docs_consistency.py\ (322 passed).

Comment on lines +123 to +126
const cleaned = String(name || "")
.trim()
.replace(JOB_SAFE_RE, "-")
.replace(/^[-/]+|[-/]+$/g, "");
parsed_routes = json.loads(routes_seen_json)
if isinstance(parsed_routes, dict):
distinct_routes.update(str(k) for k in parsed_routes)
except ValueError:
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.

Attribute runtime hits to live traffic (route, auth state)

2 participants