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

Ignore missing csp if page is not xss capable #3126

Merged
merged 19 commits into from
Jul 1, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion octopoes/bits/missing_headers/missing_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,26 @@
from octopoes.models.ooi.web import HTTPHeader, HTTPResource


def is_xss_capable(content_type: str) -> bool:
"""Determine if the content type indicates XSS capability."""
xss_capable_types = [
"text/html",
"application/xhtml+xml",
"application/xml",
"text/xml",
"text/plain",
"image/svg+xml",
]
noamblitz marked this conversation as resolved.
Show resolved Hide resolved
main_type = content_type.split(";")[0].strip().lower()
return main_type in xss_capable_types


def run(resource: HTTPResource, additional_oois: list[HTTPHeader], config: dict[str, Any]) -> Iterator[OOI]:
if not additional_oois:
return

header_keys = [header.key.lower() for header in additional_oois]
header_dict = {header.key.lower(): header.value for header in additional_oois}
noamblitz marked this conversation as resolved.
Show resolved Hide resolved

if "location" in header_keys:
return
Expand All @@ -25,7 +40,7 @@ def run(resource: HTTPResource, additional_oois: list[HTTPHeader], config: dict[
)
yield finding

if "content-security-policy" not in header_keys:
if "content-security-policy" not in header_keys and is_xss_capable(header_dict.get("content-type", "")):
ft = KATFindingType(id="KAT-NO-CSP")
finding = Finding(
finding_type=ft.reference,
Expand Down