Security-header modules never report a header that is missing (only when present-but-weak)
Summary The HTTP engine cannot evaluate a response condition for a header that is absent. When a module checks a header that the target did not send, the engine always records "no match", regardless of the condition's reverse flag. As a result, the security-header modules only fire when the header is present with a weak value, and never when the header is missing entirely — the opposite of what an auditor expects, since a missing security header is at least as serious as a misconfigured one.
This is a single root cause in nettacker/core/lib/http.py affecting every headers condition. It is most clearly visible in the three modules whose only condition is the header:
strict_transport_security_vuln content_type_options_vuln x_xss_protection_vuln Root cause In response_conditions_matched() (nettacker/core/lib/http.py, lines ~97–115):
for header in conditions["headers"]: reverse = conditions["headers"][header]["reverse"] try: regex = re.findall( re.compile(conditions["headers"][header]["regex"]), response["headers"][header.lower()] if header.lower() in response["headers"] else False, # <-- absent header -> False ) condition_results["headers"][header] = reverse_and_regex_condition(regex, reverse) except TypeError: condition_results["headers"][header] = [] # <-- re.findall(regex, False) lands here When the header is absent, the value passed to re.findall() is False, which raises TypeError; the except then sets the result to [] (i.e. "did not match"). The condition's own regex and reverse are never actually evaluated for the missing case, so a module can never flag a header as missing.
Note the content_security_policy_vuln header regex is ^.{0,0}$|unsafe-\S+ — the ^.{0,0}$ alternative is written specifically to match an empty/missing CSP value, which shows the intent was for an absent header to be caught. The engine defeats that intent.
Steps to reproduce Offline, deterministic — runs the modules' own conditions through Nettacker's real matcher, no network or servers:
import copy from nettacker.core.lib.http import response_conditions_matched from nettacker.core.template import TemplateLoader from nettacker.core.utils.common import expand_module_steps
CASES = [ ("strict_transport_security_vuln", "Strict-Transport-Security", "max-age=0"), ("content_type_options_vuln", "X-Content-Type-Options", "sniff"), ("x_xss_protection_vuln", "X-XSS-Protection", "0"), ("content_security_policy_vuln", "Content-Security-Policy", "default-src 'unsafe-inline'"), ("clickjacking_vuln", "X-Frame-Options", "ALLOWALL"), ] inputs = {"target": "t", "user_agent": "UA", "schema": None, "ports": None, "timeout": 3.0} base = {"reason": "OK", "url": "http://t/", "status_code": "200", "content": "x", "responsetime": 0.1}
print(f"{'module':34} {'header MISSING':>16} {'header WEAK':>14}") for module, header, weak in CASES: step = expand_module_steps(TemplateLoader(module, inputs).load()["payloads"])[0]["steps"][0][0] missing = dict(base, headers={"Server": "nginx"}) weak_resp = dict(base, headers={"Server": "nginx", header: weak}) rm = bool(response_conditions_matched(copy.deepcopy(step), copy.deepcopy(missing))) rw = bool(response_conditions_matched(copy.deepcopy(step), copy.deepcopy(weak_resp))) print(f"{module:34} {('REPORTED' if rm else 'not reported'):>16} {('REPORTED' if rw else 'not reported'):>14}") Output on current master:
module header MISSING header WEAK strict_transport_security_vuln not reported REPORTED content_type_options_vuln not reported REPORTED x_xss_protection_vuln not reported REPORTED content_security_policy_vuln REPORTED REPORTED clickjacking_vuln not reported not reported The same result appears in a real scan: a local HTTP server that sends no security headers produces zero findings from these modules, while a server that sends the same headers with weak values is flagged.
Expected vs actual Expected: a target missing Strict-Transport-Security / X-Content-Type-Options / X-XSS-Protection is reported by the corresponding module (missing is at least as bad as weak). Actual: missing headers are silently treated as "fine"; only present-but-weak headers are reported. Related, with extra confounding conditions clickjacking_vuln uses condition_type: and and requires both X-Frame-Options and Content-Security-Policy to be present; by the same root cause, if either is absent the module returns nothing. So the common clickjackable case — a site that sends neither header — is never flagged (repro: "not reported" in both columns). content_security_policy_vuln is subject to the same root cause for its header check, but has a second content condition under condition_type: or that can match independently of the CSP header, so its result is driven by the response body rather than the header (repro: "REPORTED" in both columns). That is a separate accuracy concern. Suggested direction (open to maintainers' preference) Treat an absent header as an empty string rather than False, so the condition's regex/reverse is actually evaluated (matching the intent already encoded in the CSP module's ^.{0,0}$). The three single-header modules' regexes would then need to also match the empty/missing case (e.g. permit empty, or add an explicit "absent" check). This needs engine + module changes together, with tests that include a no-false-positive control (a correctly configured server must not be flagged).
Environment Nettacker: current master Python: 3.11 OS: Linux
Hi! I'd be interested in investigating and working on this issue.
From the reported reproduction, it looks like missing response headers are currently passed as False to re.findall(), causing the condition to be treated as a non-match rather than evaluating the missing-header case.
I'd like to investigate the interaction between header matching, the reverse flag, and the affected security-header modules, and work on a focused fix with regression tests covering missing, weak, and correctly configured headers.
Would the maintainers be happy for me to take this on?
Thanks!
Hi @securestep9,
I wanted to clarify that I may have misunderstood the contribution workflow when I initially submitted my PR. I hadn't realised that the issue assignment and approval process needed to be completed before proceeding with a contribution.
I certainly didn't intend to step on anyone's toes or interfere with your work on this issue. In light of this, I'll step back from my proposed implementation and leave it to you and the maintainers to take things forward.
That said, I'd be more than happy to help with any technical discussions, testing, suggestions, or review if needed.
Thanks for your understanding, and apologies for any confusion!
Hi, I ran into the same root cause independently while reading response_conditions_matched() and have a tested fix locally. A few findings that go beyond the description above, in case they help whoever takes this:
-
clickjacking_vuln can't fire even when both headers are present but weak. Its content condition is ^((?!...).)+$ without MULTILINE/DOTALL, so re.findall returns nothing for any multi-line HTML body, and with condition_type: and the module never matches a real page. The same pattern in content_security_policy_vuln only matches single-line bodies, which is why that module's result follows the body rather than the header. Both body checks look for policy delivered via , which browsers ignore for X-Frame-Options and frame-ancestors, so I'd suggest dropping them.
-
HSTS should only be checked on HTTPS. strict_transport_security_vuln also requests http://…:80. Once missing headers are reported, every plain-HTTP response would be flagged, although browsers ignore HSTS sent over HTTP.
-
x_xss_protection_vuln probably should not flag a missing header. The header is deprecated and the OWASP HTTP Headers Cheat Sheet recommends not setting it (or setting 0). Flagging its absence would report correctly configured modern sites.
-
Two subdomain_takeover_vuln signatures are affected by the same bug. Bigcartel Takeover and Github Takeover combine a body fingerprint with a host header condition using reverse: true. Servers don't send a Host response header, so under the current engine these two can never match. Any engine fix changes their behaviour, so it's worth covering with a test.
-
Alternative to the empty-string approach: treat an absent header as "regex did not match" and then apply reverse normally. reverse: false conditions behave exactly as today, and modules can express "must be present and valid" as a positive regex with reverse: true (e.g. (?i)^\snosniff\s$), which also replaces the negative lookaheads as proposed in #1521. Apart from the two takeover signatures above, no existing module uses reverse: true on a header, so nothing else changes.
What I've got locally is the engine change, the four modules rewritten that way (HSTS, X-Content-Type-Options, clickjacking, CSP), updated docs/Modules.md / docs/Developers.md, and 39 unit tests (15 fail on current master, all pass with the fix), plus a before/after scan against local servers with and without the headers (no findings on the correctly configured ones).
@securestep9 I'm happy to open a PR if you'd like to assign this to me. If it goes to @Sickwoman or @TheNightCoder21 instead, feel free to use any of the above.
Tested only against servers on my own machine. OS: Windows 11, Python 3.12.
As you mentioned that it is Under review so should I assume that it has been assigned to me? @securestep9