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`.