Skip to content

fix(RatFireWall): repair broken firewall engine, import crash, and silent-no-op rules - #14

Open
sudo-ai-git wants to merge 1 commit into
The-XSS-Rat:masterfrom
sudo-ai-git:fix/ratfirewall-injection-noop-and-import-crash
Open

fix(RatFireWall): repair broken firewall engine, import crash, and silent-no-op rules#14
sudo-ai-git wants to merge 1 commit into
The-XSS-Rat:masterfrom
sudo-ai-git:fix/ratfirewall-injection-noop-and-import-crash

Conversation

@sudo-ai-git

Copy link
Copy Markdown

What's broken and why this fixes it

The RatFireWall proxy (especially moreSecureButNotFullySecure/) had several
bugs that made it dead on arrival:

  1. rules.py failed to import. Rule("Block requests with too large request body", max_request_size=2048) passed a keyword the constructor never accepted, so the whole module raised TypeError before the proxy could use it.
  2. proxy.py never started. The trailing proxy.run was missing parentheses and called a method Proxy doesn't have. (Also, mitmproxy addons are loaded via a module-level addons list + mitmdump -s, not run as python proxy.py.)
  3. The firewall was a silent no-op. matches_request/matches_response returned False on every path except the exact-lowercase <script> match. So the cURL, Set-Cookie, API-key, JWT, Referer and blacklist-user-agent rules never blocked anything.
  4. List-valued header rules never matched (string vs list comparison).
  5. <script> detection bypassable — case-sensitive and exact-only, so <SCRIPT> and <script src=...> slipped through.
  6. HorridAPIResponseFirewall raised KeyError when a response had no Content-Type, and crashed on non-JSON POST/PUT bodies.

What this PR changes

  • rules.py imports cleanly; Rule now has working blocklist semantics (request_headers/response_headers) and allowlist semantics (require_headers) so "Block ..." and "Require ..." rules mean what their names say.
  • Replaced 5 name-only placeholder rules with a single real block_attack_patterns rule (SQLi, XSS event handlers, path traversal, command injection, RFI), hardened so it does not false-positive on benign traffic (JSON, URLs, inline code).
  • Made <script> detection case- and attribute-tolerant.
  • Wired proxy.py + firewall.py as proper mitmproxy addons (addons = [...], mitmdump -s proxy.py).
  • Fixed the Horrid variant's KeyError on missing Content-Type and its crash on non-JSON bodies.
  • Added a 35-check regression test (test_firewall.py) that runs without mitmproxy installed.
  • Updated the RatFireWall readme.md with the correct run instructions.

Verification

python3 RatFireWall/test_firewall.py35/35 PASS (rules import, proxy 403 behaviour, attack-pattern true positives + false-positive rejection, <script> bypass hardening).

Scope note

This is a learning/development firewall, not a production WAF. The attack-signature list is a deliberately conservative subset; I kept the existing security-posture caveats in the README rather than over-claiming.

The moreSecureButNotFullySecure proxy was dead end-to-end:

- rules.py failed to import: Rule('...', max_request_size=2048) passed a
  kwarg the constructor never accepted (TypeError at module top).
- proxy.py never started: trailing 'proxy.run' was both missing parens and
  called a nonexistent method; mitmproxy addons load via a module-level
  'addons' list, which was absent.
- matches_request/matches_response returned False on every path except an
  exact-lowercase <script>, so the cURL, Set-Cookie, API-key, JWT, Referer
  and blacklist-user-agent rules were silent no-ops -- a firewall that
  stopped nothing.
- List-valued header rules (User-Agent: [BadBot, EvilBot]) compared a string
  to a list and so never matched.
- <script> detection was case-sensitive and exact-only; <SCRIPT> and
  <script src=...> bypassed it.
- HorridAPIResponseFirewall raised KeyError on missing Content-Type and
  crashed on non-JSON POST/PUT bodies.

This change:
- makes rules.py import cleanly and gives Rule working blocklist
  (request_headers/response_headers) AND allowlist (require_headers)
  semantics so 'Block ...' and 'Require ...' rules mean what they say,
- replaces 5 name-only placeholder rules with a real block_attack_patterns
  detector (SQLi, XSS event handlers, path traversal, command injection,
  RFI) hardened against false positives on benign traffic,
- makes <script> detection case- and attribute-tolerant,
- wires proxy.py + firewall.py as proper mitmproxy addons (module-level
  'addons') runnable via 'mitmdump -s',
- adds a 35-check regression test (test_firewall.py) that runs without
  mitmproxy installed.

Tested: python3 RatFireWall/test_firewall.py -> 35/35 PASS.
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