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

Feature/disallowed domains in csp #2624

Merged
merged 31 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b696abd
fix architecture check
noamblitz Mar 7, 2024
2d10f73
fix set clearence leven from boefje detail
noamblitz Mar 8, 2024
d026b18
bit: check for disallowed domains in csp
noamblitz Mar 8, 2024
2baa2c6
Merge branch 'main' into feature/disallowed-domains-in-csp
noamblitz Mar 8, 2024
260ea01
fix integration tests
noamblitz Mar 8, 2024
cac231d
Merge branch 'feature/disallowed-domains-in-csp' of https://github.co…
noamblitz Mar 8, 2024
b5b371e
url shorteners optional
noamblitz Mar 11, 2024
347c6f9
Merge branch 'main' into feature/disallowed-domains-in-csp
noamblitz Mar 11, 2024
3413c0a
add unit tests
noamblitz Mar 11, 2024
60fc2af
Update octopoes/bits/ask_disallowed_domains/question_schema.json
noamblitz Mar 12, 2024
4bc3696
Update octopoes/bits/disallowed_csp_hostnames/disallowed_csp_hostname…
noamblitz Mar 12, 2024
296599b
Update octopoes/tests/test_disallowed_csp_hostnames.py
noamblitz Mar 12, 2024
96cb734
Update octopoes/bits/disallowed_csp_hostnames/disallowed_csp_hostname…
noamblitz Mar 12, 2024
18eb10c
more specific checks
noamblitz Mar 12, 2024
7100992
Merge branch 'feature/disallowed-domains-in-csp' of https://github.co…
noamblitz Mar 12, 2024
aff388a
update unit tests
noamblitz Mar 12, 2024
dd5849b
allow all dicts for config
noamblitz Mar 12, 2024
a19f6ee
Update jsonSchemaToForm.js, add boolean type support
underdarknl Mar 12, 2024
49baf89
Update jsonSchemaToForm.js
underdarknl Mar 12, 2024
eb71b57
Merge branch 'main' into feature/disallowed-domains-in-csp
underdarknl Mar 13, 2024
27d6451
Merge branch 'main' into feature/disallowed-domains-in-csp
underdarknl Mar 13, 2024
eccdbc7
Merge branch 'main' into feature/disallowed-domains-in-csp
noamblitz Mar 14, 2024
2905bfe
Merge branch 'main' into feature/disallowed-domains-in-csp
ammar92 Mar 20, 2024
1ae9aba
Fixed merge conflict
ammar92 Mar 20, 2024
24e9dae
Merge branch 'main' into feature/disallowed-domains-in-csp
stephanie0x00 Mar 20, 2024
31980f8
stricter config types
noamblitz Mar 28, 2024
81417f3
Merge branch 'main' into feature/disallowed-domains-in-csp
underdarknl Mar 29, 2024
fc7f22c
Merge branch 'main' into feature/disallowed-domains-in-csp
underdarknl Mar 29, 2024
0b01ec8
Merge branch 'main' into feature/disallowed-domains-in-csp
noamblitz Apr 2, 2024
86004ef
Merge branch 'main' into feature/disallowed-domains-in-csp
underdarknl Apr 3, 2024
35fbde6
Merge branch 'main' into feature/disallowed-domains-in-csp
underdarknl Apr 4, 2024
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
10 changes: 10 additions & 0 deletions boefjes/boefjes/plugins/kat_answer_parser/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ def run(normalizer_meta: NormalizerMeta, raw: bytes | str) -> Iterable[OOI]:
bit_id="port-classification-ip",
config=json.loads(raw),
)

if "/bit/disallowed-csp-hostnames" in mime_types:
noamblitz marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(raw, bytes):
raw = raw.decode()

yield Config(
ooi=normalizer_meta.raw_data.boefje_meta.input_ooi,
bit_id="disallowed-csp-hostnames",
config=json.loads(raw),
)
Original file line number Diff line number Diff line change
Expand Up @@ -467,5 +467,10 @@
"risk": "low",
"impact": "All Certificate Authorities may issue certificates for you domain.",
"recommendation": "Set a CAA record to limit which CA's are allowed to issue certs."
},
"KAT-DISALLOWED-DOMAIN-IN-CSP": {
"description": "This CSP header contains domains that are not allowed",
"risk": "high",
"recommendation": "Remove the hostname from the CSP header"
}
}
Empty file.
20 changes: 20 additions & 0 deletions octopoes/bits/ask_disallowed_domains/ask_disallowed_domains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import json
from collections.abc import Iterator
from pathlib import Path

from octopoes.models import OOI
from octopoes.models.ooi.network import Network
from octopoes.models.ooi.question import Question


def run(
input_ooi: Network,
additional_oois: list,
config: dict[str, str],
) -> Iterator[OOI]:
network = input_ooi

with (Path(__file__).parent / "question_schema.json").open() as f:
schema = json.load(f)

yield Question(ooi=network.reference, schema_id=schema["$id"], json_schema=json.dumps(schema))
10 changes: 10 additions & 0 deletions octopoes/bits/ask_disallowed_domains/bit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from bits.definitions import BitDefinition
from octopoes.models.ooi.network import Network

BIT = BitDefinition(
id="ask-disallowed-domains",
consumes=Network,
parameters=[],
min_scan_level=0,
module="bits.ask_disallowed_domains.ask_disallowed_domains",
)
21 changes: 21 additions & 0 deletions octopoes/bits/ask_disallowed_domains/question_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "/bit/disallowed-csp-hostnames",
"type": "object",
"default": {},
"Port Configuration": "Root Schema",
"required": [],
"properties": {
"disallowed_hostnames": {
noamblitz marked this conversation as resolved.
Show resolved Hide resolved
"description": "Comma separated list of disallowed hostnames in CSP headers",
"type": "string",
"pattern": "^(\\s*(,*)[^,]+,?\\s*)*$",
"default": "github.com,google.com"
},
"disallow_url_shorteners": {
"description": "Do you want to disallow url shorteners in csp headers?",
"type": "boolean",
"default": true
}
}
}
Empty file.
10 changes: 10 additions & 0 deletions octopoes/bits/disallowed_csp_hostnames/bit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from bits.definitions import BitDefinition
from octopoes.models.ooi.web import HTTPHeaderHostname

BIT = BitDefinition(
id="disallowed-csp-hostnames",
consumes=HTTPHeaderHostname,
parameters=[],
module="bits.disallowed_csp_hostnames.disallowed_csp_hostnames",
config_ooi_relation_path="HTTPHeaderHostname.hostname.network",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import logging
from collections.abc import Iterator

from link_shorteners import link_shorteners_list

from octopoes.models import OOI
from octopoes.models.ooi.findings import Finding, KATFindingType
from octopoes.models.ooi.web import HTTPHeaderHostname

LINK_SHORTENERS = link_shorteners_list()

logger = logging.getLogger(__name__)


def get_disallowed_hostnames_from_config(config, config_key, default):
disallowed_hostnames = config.get(config_key, None)
if disallowed_hostnames is None:
return default
return list(disallowed_hostnames.strip().split(",")) if disallowed_hostnames else []


def run(input_ooi: HTTPHeaderHostname, additional_oois: list, config: dict[str, str]) -> Iterator[OOI]:
header_hostname = input_ooi
header = header_hostname.header

if header.tokenized.key.lower() != "content-security-policy":
return

disallow_url_shorteners = config.get("disallow_url_shorteners", True) if config else True

hostname = header_hostname.hostname.tokenized.name
disallowed_domains = link_shorteners_list() if disallow_url_shorteners else []
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
528 changes: 271 additions & 257 deletions octopoes/poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions octopoes/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jsonschema = "^4.18.0"
opentelemetry-instrumentation = "^0.41b0"
opentelemetry-instrumentation-psycopg2 = "^0.41b0"
pydantic-settings = "^2.0.3"
# required by disallowed-csp-hostnames bit
link-shorteners = "^1.0.7"

[tool.poetry.group.dev.dependencies]
requests-mock = "^1.10.0"
Expand Down
Loading
Loading