Skip to content

Comments

cli: export tools.cli.main; security.audit: capture HTTPError, fix subdomain base and CORS scoring#20

Merged
Victor-Dixon merged 1 commit intomainfrom
codex/triage-ci-failure-for-swarm-integration
Dec 31, 2025
Merged

cli: export tools.cli.main; security.audit: capture HTTPError, fix subdomain base and CORS scoring#20
Victor-Dixon merged 1 commit intomainfrom
codex/triage-ci-failure-for-swarm-integration

Conversation

@Victor-Dixon
Copy link
Owner

@Victor-Dixon Victor-Dixon commented Dec 31, 2025

Motivation

  • Restore the from tools.cli import main import contract so test collection and tooling that expect main succeed.
  • Ensure the security audit tool preserves useful HTTP response status codes (e.g. 429/401/403) instead of collapsing them into transport errors.
  • Improve subdomain probing by deriving an apex/base domain so probes like api.example.com work when target host is www.example.com.
  • Correct CORS scoring so missing Access-Control-Allow-Origin is not penalized while a wildcard (*) is.

Description

  • Add a lightweight CLI entrypoint wrapper at tools/cli/main.py and a module runner at tools/cli/__main__.py, and re-export main from tools/cli/__init__.py so from tools.cli import main resolves.
  • Enhance tools_v2/categories/security_audit_tools.py with _fetch_status that catches HTTPError and returns numeric status and Retry-After headers, and add _apex_domain to compute an apex host for subdomain probes.
  • Refactor probes to use _fetch_status for rate-limit and endpoint probing, preserve non-404 status codes (including 401/403/5xx) and filter out only 404/error where appropriate.
  • Update scoring: do not penalize missing Access-Control-Allow-Origin, but deduct for wildcard * origins.

Testing

  • No automated tests were executed in this session; pytest was not run locally against the changes.
  • Sanity checks were performed by inspecting tests/test_toolbelt.py which expects from tools.cli import main, and tools/cli/__init__.py now exposes main to satisfy that contract.
  • Kept tools_v2/categories/security_audit_tools.py under the project guidance limit (file length is 397 lines) to respect the <400 LOC constraint.
  • Recommend running pytest -q (and pytest tests/test_toolbelt.py -q) and any CI linting before merge to validate runtime behavior and lint rules.

Codex Task


Note

Improves CLI entrypoints and hardens the security audit tool.

  • CLI: Add tools/cli/main.py wrapper and tools/cli/__main__.py for python -m tools.cli; re-export main from tools/cli/__init__.py to restore from tools.cli import main.
  • Security audit: Introduce _fetch_status to preserve HTTP statuses (incl. HTTPError) and Retry-After; refactor rate-limit and endpoint probes to use it and filter only 404/errors.
  • Subdomain probing: Add _apex_domain and use it in _probe_subdomains to form correct FQDNs.
  • Scoring: Do not penalize missing Access-Control-Allow-Origin; deduct when wildcard * is present.
  • Minor cleanups: condensed constants, small parsing/typing tweaks.

Written by Cursor Bugbot for commit 6f39a58. Configure here.

@Victor-Dixon Victor-Dixon merged commit c10be05 into main Dec 31, 2025
1 of 2 checks passed
@Victor-Dixon Victor-Dixon deleted the codex/triage-ci-failure-for-swarm-integration branch December 31, 2025 23:07
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +27 to +31
COMMON_PUBLIC_SUFFIX_2 = {"co.uk", "org.uk", "ac.uk", "gov.uk", "com.au", "net.au", "org.au", "co.nz", "org.nz"}
COMMON_HOST_PREFIXES = {"www", "m", "app", "beta"}


def _apex_domain(host: str) -> str:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid probing unrelated domains for public-suffix hosts

The new _apex_domain logic relies on a short hard-coded public-suffix list, so for targets hosted under other public suffixes (e.g. user.github.io, myapp.herokuapp.com, foo.cloudfront.net), the apex becomes the shared suffix (github.io, herokuapp.com, etc.). _probe_subdomains will then enumerate subdomains of that unrelated apex, producing false positives and potentially scanning off-target domains. This is a regression from probing within the original host and will mislead results whenever the suffix isn’t in COMMON_PUBLIC_SUFFIX_2.

Useful? React with 👍 / 👎.

if parts[0] in COMMON_HOST_PREFIXES:
parts = parts[1:]
if len(parts) <= 2:
return ".".join(parts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex domain strips legitimate domain at two-level TLDs

The _apex_domain function incorrectly handles domains where a common host prefix (www, m, app, beta) is actually the legitimate apex domain at a two-level TLD. For example, input m.co.uk gets stripped to co.uk because m is in COMMON_HOST_PREFIXES, but co.uk is just a public suffix. The check at lines 40-41 returns early without verifying the remaining parts aren't a known public suffix from COMMON_PUBLIC_SUFFIX_2. This causes _probe_subdomains to probe wrong domains like www.co.uk instead of www.m.co.uk.

Fix in Cursor Fix in Web

suffix2 = ".".join(parts[-2:])
if suffix2 in COMMON_PUBLIC_SUFFIX_2 and len(parts) >= 3:
return ".".join(parts[-3:])
return ".".join(parts[-2:])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete suffix list breaks apex extraction for many countries

The COMMON_PUBLIC_SUFFIX_2 set only contains UK, AU, and NZ two-level TLDs, missing many common ones like .com.br, .co.jp, .com.cn, .com.mx, .com.ar, etc. For domains at these unlisted TLDs, _apex_domain falls back to returning the last two parts, which is the public suffix rather than the apex domain. For example, example.com.br returns com.br instead of example.com.br. This causes _probe_subdomains to probe completely wrong domains like www.com.br instead of www.example.com.br.

Additional Locations (1)

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant