From 06f2977c1dd15b2a31018688798e3941c4d92e48 Mon Sep 17 00:00:00 2001 From: Emmanuel Gautier Date: Tue, 17 Nov 2026 00:23:39 +0100 Subject: [PATCH] feat: follow the harnessx check pack contract and embed cache-detective --- cmd/scan.go | 31 +++-- docs/checks/accesscontrol.mdx | 12 +- docs/checks/caching.mdx | 18 +-- docs/checks/disclosure.mdx | 16 +-- docs/checks/headers.mdx | 32 ++--- docs/checks/headertrust.mdx | 28 ++-- docs/checks/index.mdx | 2 +- docs/checks/protocol.mdx | 4 +- docs/checks/ratelimit.mdx | 12 +- docs/checks/smuggling.mdx | 4 +- docs/checks/ssrf.mdx | 8 +- docs/checks/templateinjection.mdx | 4 +- docs/checks/tls.mdx | 20 +-- docs/checks/waf.mdx | 14 +- go.mod | 12 +- go.sum | 12 ++ proxy/checks.go | 23 ++-- .../accesscontrol/method_bypass/check.yaml | 2 +- .../nginx_alias_traversal/check.yaml | 4 +- .../accesscontrol/path_bypass/check.yaml | 2 +- proxy/checks/caching/adapt/adapt.go | 114 ---------------- .../caching/authenticated_caching/check.go | 33 +---- .../caching/authenticated_caching/check.yaml | 4 +- proxy/checks/caching/cache_deception/check.go | 21 +-- .../checks/caching/cache_deception/check.yaml | 4 +- proxy/checks/caching/cache_poisoning/check.go | 23 +--- .../checks/caching/cache_poisoning/check.yaml | 4 +- proxy/checks/caching/caching.go | 128 ++++++++++++++++++ proxy/checks/caching/caching_test.go | 47 ++++--- .../checks/caching/vary_consistency/check.go | 18 +-- .../caching/vary_consistency/check.yaml | 4 +- .../disclosure/config_exposure/check.yaml | 2 +- .../disclosure/directory_listing/check.yaml | 2 +- .../disclosure/exposed_management/check.yaml | 2 +- .../disclosure/verbose_errors/check.yaml | 2 +- .../headers/content_type_options/check.yaml | 4 +- proxy/checks/headers/cookie_flags/check.yaml | 4 +- proxy/checks/headers/cors/check.yaml | 2 +- proxy/checks/headers/csp/check.yaml | 4 +- proxy/checks/headers/frame_options/check.yaml | 4 +- .../headers/permissions_policy/check.yaml | 4 +- .../checks/headers/referrer_policy/check.yaml | 4 +- proxy/checks/headers/server_banner/check.yaml | 4 +- .../checks/headertrust/acl_bypass/check.yaml | 2 +- .../forwarded_consistency/check.yaml | 2 +- .../host_header_injection/check.yaml | 2 +- .../headertrust/true_client_ip/check.yaml | 2 +- .../headertrust/vhost_confusion/check.yaml | 2 +- .../headertrust/x_forwarded_for/check.yaml | 2 +- .../headertrust/x_forwarded_host/check.yaml | 2 +- proxy/checks/headertrust/x_real_ip/check.yaml | 2 +- .../protocol/h2_authority_trust/check.yaml | 4 +- .../ratelimit/missing_throttling/check.yaml | 4 +- .../ratelimit/oversized_header/check.yaml | 4 +- .../ratelimit/spoofed_ip_bypass/check.yaml | 4 +- .../smuggling/ambiguous_framing/check.yaml | 4 +- .../ssrf/internal_target_access/check.yaml | 4 +- .../checks/ssrf/open_forward_proxy/check.yaml | 4 +- .../templateinjection/header_ssti/check.yaml | 4 +- proxy/checks/tls/certificate/check.yaml | 4 +- proxy/checks/tls/cipher_strength/check.yaml | 4 +- proxy/checks/tls/hsts/check.yaml | 4 +- proxy/checks/tls/https_redirect/check.yaml | 2 +- proxy/checks/tls/protocol_version/check.yaml | 4 +- proxy/checks/waf/baseline_payloads/check.yaml | 2 +- .../waf/content_type_consistency/check.yaml | 2 +- proxy/checks/waf/encoding_bypass/check.yaml | 2 +- proxy/checks_test.go | 2 +- proxy/probebase/httpfetch.go | 4 +- proxy/probebase/tlsinfo.go | 4 +- 70 files changed, 369 insertions(+), 411 deletions(-) delete mode 100644 proxy/checks/caching/adapt/adapt.go create mode 100644 proxy/checks/caching/caching.go diff --git a/cmd/scan.go b/cmd/scan.go index 2ecaa4a..046929d 100644 --- a/cmd/scan.go +++ b/cmd/scan.go @@ -1,6 +1,7 @@ package cmd import ( + "context" "fmt" "github.com/cerberauth/harnessx" @@ -84,6 +85,8 @@ Use only against systems you own or have explicit written permission to test.`, } checks, defs := proxy.AllChecks() + var fetchErr error + recordFetchErr(checks, &fetchErr) reportxReporter := harnessreport.New(ctx, harnessreport.Config{ ToolName: name, @@ -120,7 +123,7 @@ Use only against systems you own or have explicit written permission to test.`, // couldn't be reached at all — every dependent check then // skips rather than erroring, which would otherwise look // exactly like "reached the target, found nothing". - if fetchErr := sharedFetchErr(summary); fetchErr != nil { + if fetchErr != nil { return &RuntimeError{err: fmt.Errorf("connecting to target: %w", fetchErr)} } @@ -139,21 +142,25 @@ Use only against systems you own or have explicit written permission to test.`, return scanCmd } -// sharedFetchErr returns probe.http_fetch's underlying error, if any, by -// scanning summary.Results — the shared fetch stores its error on Result.Data -// rather than Result.Err (so dependent checks can Skip cleanly instead of -// erroring), which would otherwise make total unreachability -// indistinguishable from "reached the target, found nothing". -func sharedFetchErr(summary harnessx.ScanSummary) error { - for _, r := range summary.Results { - if r.CheckID != probebase.HTTPFetchCheckID { +// recordFetchErr makes the internal shared fetch report its underlying error +// to dst: it stores it on Result.Data rather than Result.Err (so dependent +// checks can Skip cleanly instead of erroring), which would otherwise make +// total unreachability indistinguishable from "reached the target, found +// nothing". +func recordFetchErr(checks []harnessx.Check, dst *error) { + for i, c := range checks { + if c.ID != probebase.HTTPFetchCheckID { continue } - if fetched, ok := harnessx.DataAs[*probebase.FetchResult](r); ok && fetched.Err != nil { - return fetched.Err + run := c.Run + checks[i].Run = func(ctx context.Context, target harnessx.Target, store harnessx.ResultStore) (harnessx.Result, error) { + r, err := run(ctx, target, store) + if fetched, ok := harnessx.DataAs[*probebase.FetchResult](r); ok { + *dst = fetched.Err + } + return r, err } } - return nil } // RuntimeError marks an error as a runtime/connection failure (exit code 2) diff --git a/docs/checks/accesscontrol.mdx b/docs/checks/accesscontrol.mdx index 69aaf16..2a5e43c 100644 --- a/docs/checks/accesscontrol.mdx +++ b/docs/checks/accesscontrol.mdx @@ -5,23 +5,23 @@ description: Access control bypassed via path normalization (case variation, dup | Check ID | Title | CVSS 4.0 | CWE | OWASP | | --- | --- | --- | --- | --- | -| `accesscontrol.path_bypass` | Access Control Bypassed via Path Normalization | 8.7 | [CWE-284](https://cwe.mitre.org/data/definitions/284.html) | API5:2023 | -| `accesscontrol.method_bypass` | Access Control Bypassed via HTTP Method | 8.7 | [CWE-650](https://cwe.mitre.org/data/definitions/650.html) | API5:2023 | -| `accesscontrol.nginx_alias_traversal` | Nginx Off-by-Slash Alias Traversal | 8.7 | [CWE-22](https://cwe.mitre.org/data/definitions/22.html) | API8:2023 | +| `proxy.accesscontrol.path_bypass` | Access Control Bypassed via Path Normalization | 8.7 | [CWE-284](https://cwe.mitre.org/data/definitions/284.html) | API5:2023 | +| `proxy.accesscontrol.method_bypass` | Access Control Bypassed via HTTP Method | 8.7 | [CWE-650](https://cwe.mitre.org/data/definitions/650.html) | API5:2023 | +| `proxy.accesscontrol.nginx_alias_traversal` | Nginx Off-by-Slash Alias Traversal | 8.7 | [CWE-22](https://cwe.mitre.org/data/definitions/22.html) | API8:2023 | -## `accesscontrol.path_bypass` +## `proxy.accesscontrol.path_bypass` Probes a fixed list of common protected paths (`/admin`, `/internal`, `/private`). For any that deny a plain `GET`, it retries case/encoding/traversal variants of the same path — uppercase, a duplicate leading slash, a trailing slash or dot segment, a partially percent-encoded traversal back to itself, a double-encoded first byte, a trailing null byte, and a matrix (`;`) parameter — that a backend commonly normalizes away before routing. A variant that succeeds where the plain path was denied means the access control is matching on the raw, unnormalized path instead of the path the backend will actually resolve. **Remediate:** decode and canonicalize the path (case-fold, resolve `.`/`..` segments, collapse duplicate slashes, strip matrix parameters) using the same logic the backend router uses, before making the access-control decision — ideally by enforcing the check at the same layer that does the routing, rather than in front of it. -## `accesscontrol.method_bypass` +## `proxy.accesscontrol.method_bypass` Probes the same fixed list of common protected paths and, for any that deny a `GET`, retries the identical path with `HEAD`, `POST`, `PUT`, `PATCH`, `DELETE`, and `OPTIONS`. A verb that succeeds where `GET` was denied means the access control only gates the verb it expects instead of every verb the backend routes to that handler. **Remediate:** apply the access-control check independent of the HTTP method, or deny by default and explicitly allow only the methods a path is meant to support. -## `accesscontrol.nginx_alias_traversal` +## `proxy.accesscontrol.nginx_alias_traversal` Skipped for targets that don't fingerprint as nginx via the `Server` header. For a fixed list of common alias-style location prefixes (`/files`, `/static`, `/assets`, `/media`, `/public`, `/uploads`, `/download`), fetches `/index.html` and, if that returns `200`, also fetches `index.html` — the same filename appended directly onto the prefix with no `/` separator. Identical content on both means the `location` matching that prefix has no trailing slash, so nginx strips only the literal prefix and appends the remainder of the request path verbatim to the `alias` directory — from there, an attacker can substitute a `../` traversal for the filename to escape the aliased directory entirely (the classic [Gixy `alias_traversal`](https://github.com/yandex/gixy/blob/master/docs/en/plugins/aliastraversal.md) finding). diff --git a/docs/checks/caching.mdx b/docs/checks/caching.mdx index 06a73a6..c03fd23 100644 --- a/docs/checks/caching.mdx +++ b/docs/checks/caching.mdx @@ -5,7 +5,7 @@ description: Authenticated-response caching, cache-key/Vary consistency, unkeyed import { Aside } from '@/components/docs'; -These checks build on the same RFC 9111 (HTTP Caching) semantics as [`cache-detective`](https://github.com/cerberauth/cache-detective) — `caching.authenticated_caching` and `caching.cache_deception` reuse its `cache/checks/cacheability` cacheability determination directly, and `caching.vary_consistency` reuses its `cache/cdn` cache-status detection. +These checks are [`cache-detective`](https://github.com/cerberauth/cache-detective)'s own checks, embedded with `harnessx/embed` and run against the scanned URL: `proxy.caching.authenticated_caching` runs `cache.authenticated_cacheable`, `proxy.caching.vary_consistency` runs `cache.vary_key`, `proxy.caching.cache_poisoning` runs `cache.unkeyed_header_injection` and `proxy.caching.cache_deception` runs `cache.cache_deception`.