Feat/http api mvp#30
Open
shayankashif123 wants to merge 2 commits intoc2siorg:mainfrom
Open
Conversation
- FastAPI app with GET /health and POST /validate endpoints - In-process regex rule engine (6 rules, 24+ patterns) - Pre-filter + sidecar two-layer enforcement flow - Pydantic request/response contracts - 82 tests — all passing, no sidecar required - SDK zero-dependency contract preserved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Delivers the Cognitive Firewall MVP described in the issue —
a FastAPI HTTP interface over the existing Python SDK and UDS
sidecar, with a configurable rule-based pre-filter layer.
Closes #27
What this PR does
Before this PR, using the firewall required writing Python code
directly against the SDK. After this PR, any HTTP client can
evaluate a payload through the full enforcement stack:
Architecture decision — pre-filter + sidecar
The rule engine runs in-process before every sidecar call.
This story is clean — fast rejection first, authoritative
enforcement second. The
rule_basedflag tells the callerwhich layer made the decision.
Files changed
SDK zero-dependency contract preserved
sdk/python/pyproject.tomlis untouched.New dependencies live exclusively in
api/requirements.txt.Test output
All tests use mocks — CI passes without a running sidecar.
Live demo
Health check:
curl -s http://localhost:8000/health {"status":"ok","sidecar":"reachable"}Clean prompt — ALLOW:
Injection attempt — BLOCK (rule engine, sidecar not called):
Invalid hook — 422:
Sidecar down — 503:
What this deliberately does not include
ALLOW in Phase 1, sanitise path is correctly handled in code
and will produce real output when Phase 3 ships
On detection coverage
The rule engine is Layer 1 of a planned multi-layer stack.
Regex matching is fast and deterministic but bypassable through
paraphrasing. This is acknowledged and addressed by deeper layers:
(URL encoding, Base64, zero-width chars, Unicode variants)