Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update disallowed_csp_hostnames.py, also trigger on higher level denied domains #3980

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ def run(input_ooi: HTTPHeaderHostname, additional_oois: list, config: dict[str,
disallowed_hostnames_from_config = get_disallowed_hostnames_from_config(config, "disallowed_hostnames", [])

disallowed_domains.extend(disallowed_hostnames_from_config)

if hostname.lower() in disallowed_domains:
ft = KATFindingType(id="KAT-DISALLOWED-DOMAIN-IN-CSP")
f = Finding(ooi=input_ooi.reference, finding_type=ft.reference)
yield ft
yield f
hostnameparts = hostname.lower().split(".")

# For e.g. ["www", "example", "com"], check "www.example.com", "example.com" and "com"
for i in range(len(hostnameparts)):
if ".".join(hostnameparts[i:]) in disallowed_domains:
ft = KATFindingType(id="KAT-DISALLOWED-DOMAIN-IN-CSP")
f = Finding(ooi=input_ooi.reference, finding_type=ft.reference)
yield ft
yield f
break
20 changes: 20 additions & 0 deletions octopoes/tests/test_disallowed_csp_hostnames.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,23 @@ def test_disallowed_csp_headers_disallow_custom_hostname():
ooi=http_header_hostname.reference, finding_type=KATFindingType(id="KAT-DISALLOWED-DOMAIN-IN-CSP").reference
),
]


def test_disallowed_csp_headers_disallow_subdomains():
http_header_hostname = HTTPHeaderHostname(
hostname=Reference.from_str("Hostname|internet|subdomain.example.com"),
header=Reference.from_str(
"HTTPHeader|internet|1.1.1.1|tcp|443|https|internet|subdomain.example.com|https|internet|subdomain.example.com|443||Content-Security-Policy"
),
)

results = list(run(http_header_hostname, [], {"disallowed_hostnames": "example.com"}))

assert "subdomain" in http_header_hostname.reference

assert results == [
KATFindingType(id="KAT-DISALLOWED-DOMAIN-IN-CSP"),
Finding(
ooi=http_header_hostname.reference, finding_type=KATFindingType(id="KAT-DISALLOWED-DOMAIN-IN-CSP").reference
),
]
Loading