diff --git a/docs/checks/index.mdx b/docs/checks/index.mdx index 2ecef63..93785fb 100644 --- a/docs/checks/index.mdx +++ b/docs/checks/index.mdx @@ -18,6 +18,7 @@ import { Card, CardGrid, LinkCard } from '@/components/docs'; + ## Severity diff --git a/docs/checks/ratelimit.mdx b/docs/checks/ratelimit.mdx new file mode 100644 index 0000000..5d0963c --- /dev/null +++ b/docs/checks/ratelimit.mdx @@ -0,0 +1,61 @@ +--- +title: Rate Limiting & DoS Resilience +description: Whether the proxy throttles per client, keys its throttle on a spoofable header, and caps request header size. +--- + +import { Aside } from '@/components/docs'; + +A proxy should absorb abusive load before it reaches the backend: throttle +per client, key that throttle on the real connection peer (not a +client-supplied header), and cap request sizes. These checks measure those +properties with small, bounded probes. + + + +| Check ID | Title | CVSS 4.0 | CWE | OWASP | +| --- | --- | --- | --- | --- | +| `ratelimit.missing_throttling` | No Per-Client Request Throttling at the Proxy | 5.3 | [CWE-770](https://cwe.mitre.org/data/definitions/770.html) | API4:2023 | +| `ratelimit.spoofed_ip_bypass` | Rate Limit Bypassed via Spoofed Client-IP Header | 6.9 | [CWE-770](https://cwe.mitre.org/data/definitions/770.html) | API4:2023 | +| `ratelimit.oversized_header` | Oversized Request Headers Accepted Without a Limit | 5.3 | [CWE-770](https://cwe.mitre.org/data/definitions/770.html) | API4:2023 | + +## `ratelimit.missing_throttling` + +Sends a small burst from one client and reports when none of the requests +is throttled. Informational-to-low: throttling at the backend or an +external layer is not visible to a single-client burst. + +**Remediate:** enforce per-client request rate limiting at the proxy +(e.g. nginx `limit_req`, an API gateway plan). + +## `ratelimit.spoofed_ip_bypass` + +For a proxy that does throttle, drives it into throttling, confirms a plain +request is still throttled, then flips the response back to success by +rotating a spoofed IP in `X-Forwarded-For`, `X-Real-IP`, `True-Client-IP`, +`X-Client-IP`, or `X-Forwarded`. A header that resets the limit is a +confirmed bypass; the check skips when no throttling is observed. + +**Remediate:** key rate limiting on the real connection peer, and only +trust a client-IP header when it arrives from a known, trusted upstream +(see the Client-IP & Header Trust Boundary checks). + +## `ratelimit.oversized_header` + +Sends one request with a single 128 KiB header and flags acceptance rather +than a 431/400/413 rejection — a proxy with no header-size cap lets a client +force large per-request allocations. + +**Remediate:** set conservative request-header size limits (nginx +`large_client_header_buffers`, Apache `LimitRequestFieldSize`). + +## Not yet covered + +Slowloris / slow-body resistance and connection/keepalive limits under load +(checklist items 3 and 5) are genuine denial-of-service tests that can +degrade a live target even when bounded; they are intentionally left to a +dedicated, separately gated capability rather than running under +`--aggressive`. diff --git a/proxy/checks.go b/proxy/checks.go index 3a80a55..4683e68 100644 --- a/proxy/checks.go +++ b/proxy/checks.go @@ -37,6 +37,9 @@ import ( xforwardedfor "github.com/cerberauth/proxyaudit/proxy/checks/headertrust/x_forwarded_for" xforwardedhost "github.com/cerberauth/proxyaudit/proxy/checks/headertrust/x_forwarded_host" xrealip "github.com/cerberauth/proxyaudit/proxy/checks/headertrust/x_real_ip" + missingthrottling "github.com/cerberauth/proxyaudit/proxy/checks/ratelimit/missing_throttling" + oversizedheader "github.com/cerberauth/proxyaudit/proxy/checks/ratelimit/oversized_header" + spoofedipbypass "github.com/cerberauth/proxyaudit/proxy/checks/ratelimit/spoofed_ip_bypass" ambiguousframing "github.com/cerberauth/proxyaudit/proxy/checks/smuggling/ambiguous_framing" internaltargetaccess "github.com/cerberauth/proxyaudit/proxy/checks/ssrf/internal_target_access" openforwardproxy "github.com/cerberauth/proxyaudit/proxy/checks/ssrf/open_forward_proxy" @@ -120,6 +123,11 @@ func AllChecks() ([]harnessx.Check, map[harnessx.CheckID]checkdef.CheckDef) { internaltargetaccess.Check, // Request Smuggling / Desync (Agg-tier, --aggressive). ambiguousframing.Check, + + // Rate Limiting & DoS Resilience (Agg-tier, --aggressive). + missingthrottling.Check, + spoofedipbypass.Check, + oversizedheader.Check, } defs := map[harnessx.CheckID]checkdef.CheckDef{ @@ -171,6 +179,10 @@ func AllChecks() ([]harnessx.Check, map[harnessx.CheckID]checkdef.CheckDef) { internaltargetaccess.Check.ID: internaltargetaccess.Def, ambiguousframing.Check.ID: ambiguousframing.Def, + + missingthrottling.Check.ID: missingthrottling.Def, + spoofedipbypass.Check.ID: spoofedipbypass.Def, + oversizedheader.Check.ID: oversizedheader.Def, } return checks, defs diff --git a/proxy/checks/ratelimit/missing_throttling/check.go b/proxy/checks/ratelimit/missing_throttling/check.go new file mode 100644 index 0000000..538ad17 --- /dev/null +++ b/proxy/checks/ratelimit/missing_throttling/check.go @@ -0,0 +1,52 @@ +// Package missingthrottling sends a small, bounded burst of requests and +// reports when none of them is throttled — the proxy enforces no per-client +// request rate limit of its own, so a single client can drive unbounded +// load straight through to the backend. +// +// The finding is informational-to-low: many deployments rate-limit at the +// backend or an external layer instead, which a black-box burst from one +// client cannot see. It flags only the observable fact that the proxy +// itself did not throttle a rapid burst. +// +// Requires --aggressive: it sends a burst of requests, part of the opt-in +// attack-simulation suite. +package missingthrottling + +import ( + "context" + _ "embed" + "strconv" + + "github.com/cerberauth/harnessx" + "github.com/cerberauth/harnessx/checkdef" + "github.com/cerberauth/proxyaudit/proxy/checks/ratelimit/rlprobe" + "github.com/cerberauth/proxyaudit/proxy/probebase" + "github.com/cerberauth/proxyaudit/proxy/scanctx" +) + +//go:embed check.yaml +var checkYAML []byte + +var Def = checkdef.MustParseCheckDefYAML("missing_throttling", checkYAML) + +var Check = checkdef.NewCheck(Def, func(ctx context.Context, target harnessx.Target, _ harnessx.ResultStore) (harnessx.Result, error) { + sctx := scanctx.TargetContext(target) + if !sctx.Aggressive { + return harnessx.Result{Skipped: true, SkipReason: "aggressive-suite check — rerun with --aggressive to send a rate-limit burst"}, nil + } + + statuses, err := rlprobe.Burst(ctx, sctx, target.URL, rlprobe.BurstSize) + if err != nil { + return harnessx.Result{Err: err}, nil + } + if rlprobe.AnyThrottled(statuses) { + return harnessx.Result{}, nil + } + + return harnessx.Result{Observations: []harnessx.Observation{{ + Title: "Proxy enforces no per-client request throttling", + Description: "A burst of " + strconv.Itoa(len(statuses)) + " requests from a single client was served without any being rate-limited (no 429 or 503). The proxy applies no per-client throttling of its own, so one client can drive unbounded request load through to the backend. If rate limiting exists only at the backend or an external layer, it is not visible here and may not protect the backend from pre-auth floods.", + Evidence: strconv.Itoa(len(statuses)) + " consecutive requests, none throttled (last status " + strconv.Itoa(statuses[len(statuses)-1]) + ")", + Metadata: map[string]string{"requests": strconv.Itoa(len(statuses))}, + }}}, nil +}, checkdef.WithSkip(probebase.SkipUnlessFetched)) diff --git a/proxy/checks/ratelimit/missing_throttling/check.yaml b/proxy/checks/ratelimit/missing_throttling/check.yaml new file mode 100644 index 0000000..ab74332 --- /dev/null +++ b/proxy/checks/ratelimit/missing_throttling/check.yaml @@ -0,0 +1,13 @@ +id: "ratelimit.missing_throttling" +name: "No Per-Client Request Throttling at the Proxy" +description: "Sends a small bounded burst from a single client and reports when none of the requests is throttled (no 429/503) — the proxy enforces no per-client rate limit of its own, so one client can drive unbounded load through to the backend. Informational-to-low: rate limiting at the backend or an external layer is not visible to a single-client burst. Requires --aggressive." +link: "https://owasp.org/www-project-api-security/" +tags: + - rate-limiting + - dos +depends_on: + - "probe.http_fetch" +cvss_vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N" +cvss_score: 5.3 +cwe_id: "CWE-770" +owasp: "API4:2023" diff --git a/proxy/checks/ratelimit/oversized_header/check.go b/proxy/checks/ratelimit/oversized_header/check.go new file mode 100644 index 0000000..2f95e8a --- /dev/null +++ b/proxy/checks/ratelimit/oversized_header/check.go @@ -0,0 +1,72 @@ +// Package oversizedheader tests whether the proxy caps request header size. +// A front-end that forwards an arbitrarily large header set (rather than +// rejecting it with 431/400/413) lets a client force large per-request +// allocations on the proxy and backend — a cheap memory-pressure / DoS +// vector, and often a sign the proxy isn't buffering defensively. +// +// It sends one request carrying a single very large (128 KiB) header, +// well above typical proxy limits (nginx 8 KiB, Apache ~8 KiB) but bounded, +// and flags acceptance. It confirms an ordinary request is accepted first, +// so a target that rejects everything isn't misread. +// +// Requires --aggressive: it sends a deliberately oversized request, part of +// the opt-in attack-simulation suite. +package oversizedheader + +import ( + "context" + _ "embed" + "strconv" + "strings" + + "github.com/cerberauth/harnessx" + "github.com/cerberauth/harnessx/checkdef" + "github.com/cerberauth/proxyaudit/proxy/checks/ratelimit/rlprobe" + "github.com/cerberauth/proxyaudit/proxy/probebase" + "github.com/cerberauth/proxyaudit/proxy/scanctx" +) + +//go:embed check.yaml +var checkYAML []byte + +var Def = checkdef.MustParseCheckDefYAML("oversized_header", checkYAML) + +// headerBytes is the size of the single oversized header value — above +// common proxy caps, far below anything that could itself exhaust memory. +const headerBytes = 128 * 1024 + +var Check = checkdef.NewCheck(Def, func(ctx context.Context, target harnessx.Target, _ harnessx.ResultStore) (harnessx.Result, error) { + sctx := scanctx.TargetContext(target) + if !sctx.Aggressive { + return harnessx.Result{Skipped: true, SkipReason: "aggressive-suite check — rerun with --aggressive to send an oversized request"}, nil + } + + control, err := rlprobe.Get(ctx, sctx, target.URL, nil) + if err != nil { + return harnessx.Result{Err: err}, nil + } + if control == 0 || control >= 400 { + return harnessx.Result{Skipped: true, SkipReason: "ordinary request not accepted (status " + strconv.Itoa(control) + ") — can't tell an oversize rejection from a blanket one"}, nil + } + + oversized, err := rlprobe.Get(ctx, sctx, target.URL, map[string]string{ + "X-Proxyaudit-Pad": strings.Repeat("A", headerBytes), + }) + if err != nil { + // A transport-level refusal (connection reset/closed) is the proxy + // rejecting the oversized request — the desired behaviour. + return harnessx.Result{}, nil + } + // Rejected with a status: 431/400/413/414 (or any 4xx/5xx) is correct + // defensive handling. + if oversized == 0 || oversized >= 400 { + return harnessx.Result{}, nil + } + + return harnessx.Result{Observations: []harnessx.Observation{{ + Title: "Proxy accepts oversized request headers without a limit", + Description: "A request carrying a single " + strconv.Itoa(headerBytes/1024) + " KiB header was accepted (" + strconv.Itoa(oversized) + ") instead of being rejected with 431/400/413. The proxy enforces no request-header size cap, so a client can force large per-request allocations on the proxy and backend — a low-cost memory-pressure / denial-of-service vector.", + Evidence: strconv.Itoa(headerBytes/1024) + " KiB header -> " + strconv.Itoa(oversized) + "; ordinary request -> " + strconv.Itoa(control), + Metadata: map[string]string{"header_bytes": strconv.Itoa(headerBytes), "status": strconv.Itoa(oversized)}, + }}}, nil +}, checkdef.WithSkip(probebase.SkipUnlessFetched)) diff --git a/proxy/checks/ratelimit/oversized_header/check.yaml b/proxy/checks/ratelimit/oversized_header/check.yaml new file mode 100644 index 0000000..74fade7 --- /dev/null +++ b/proxy/checks/ratelimit/oversized_header/check.yaml @@ -0,0 +1,13 @@ +id: "ratelimit.oversized_header" +name: "Oversized Request Headers Accepted Without a Limit" +description: "Sends one request carrying a single 128 KiB header — above common proxy caps (nginx/Apache ~8 KiB) but bounded — and flags acceptance (not a 431/400/413 rejection). A proxy with no header-size cap lets a client force large per-request allocations, a low-cost memory-pressure / DoS vector. Confirms an ordinary request is accepted first. Requires --aggressive." +link: "https://owasp.org/www-project-api-security/" +tags: + - rate-limiting + - dos +depends_on: + - "probe.http_fetch" +cvss_vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N" +cvss_score: 5.3 +cwe_id: "CWE-770" +owasp: "API4:2023" diff --git a/proxy/checks/ratelimit/ratelimit_test.go b/proxy/checks/ratelimit/ratelimit_test.go new file mode 100644 index 0000000..9b13547 --- /dev/null +++ b/proxy/checks/ratelimit/ratelimit_test.go @@ -0,0 +1,147 @@ +// Package ratelimit_test exercises the checks/ratelimit scanners against +// httptest servers modelling different throttling behaviours, driven +// through a harnessx.Engine as proxyaudit would. +package ratelimit_test + +import ( + "context" + "net/http" + "net/http/httptest" + "sync" + "testing" + + "github.com/cerberauth/harnessx" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + missingthrottling "github.com/cerberauth/proxyaudit/proxy/checks/ratelimit/missing_throttling" + oversizedheader "github.com/cerberauth/proxyaudit/proxy/checks/ratelimit/oversized_header" + spoofedipbypass "github.com/cerberauth/proxyaudit/proxy/checks/ratelimit/spoofed_ip_bypass" + "github.com/cerberauth/proxyaudit/proxy/probebase" + "github.com/cerberauth/proxyaudit/proxy/scanctx" +) + +const limit = 8 + +func run(t *testing.T, srv *httptest.Server, aggressive bool, check harnessx.Check) harnessx.ScanSummary { + t.Helper() + target := scanctx.NewTarget(srv.URL, &scanctx.ScanContext{HTTPClient: srv.Client(), Aggressive: aggressive}) + engine := harnessx.New(harnessx.WithChecks(probebase.HTTPFetchCheck, check)) + summary, err := engine.Run(context.Background(), target) + require.NoError(t, err) + return summary +} + +func noLimit() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) }) +} + +// perClientLimit throttles after `limit` requests sharing the same key, +// where the key is the X-Forwarded-For header if present, else the peer — +// the misconfiguration the bypass check looks for. +func perClientLimit() http.Handler { + var mu sync.Mutex + seen := map[string]int{} + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + key := r.Header.Get("X-Forwarded-For") + if key == "" { + key = "peer" + } + mu.Lock() + seen[key]++ + over := seen[key] > limit + mu.Unlock() + if over { + w.WriteHeader(http.StatusTooManyRequests) + return + } + w.WriteHeader(http.StatusOK) + }) +} + +// globalLimit throttles after `limit` total requests regardless of any +// client-supplied header — correct keying, nothing to bypass. +func globalLimit() http.Handler { + var mu sync.Mutex + var n int + return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + mu.Lock() + n++ + over := n > limit + mu.Unlock() + if over { + w.WriteHeader(http.StatusTooManyRequests) + return + } + w.WriteHeader(http.StatusOK) + }) +} + +func rejectBigHeader() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if len(r.Header.Get("X-Proxyaudit-Pad")) > 8192 { + w.WriteHeader(http.StatusRequestHeaderFieldsTooLarge) + return + } + w.WriteHeader(http.StatusOK) + }) +} + +func TestMissingThrottling_NoLimit_Flagged(t *testing.T) { + srv := httptest.NewServer(noLimit()) + defer srv.Close() + assert.Len(t, run(t, srv, true, missingthrottling.Check).Observations, 1) +} + +func TestMissingThrottling_Throttled_NoFindings(t *testing.T) { + srv := httptest.NewServer(globalLimit()) + defer srv.Close() + assert.Empty(t, run(t, srv, true, missingthrottling.Check).Observations) +} + +func TestMissingThrottling_NotAggressive_Skipped(t *testing.T) { + srv := httptest.NewServer(noLimit()) + defer srv.Close() + assert.True(t, skipped(run(t, srv, false, missingthrottling.Check), missingthrottling.Check.ID)) +} + +func TestSpoofedIPBypass_PerClientKey_Flagged(t *testing.T) { + srv := httptest.NewServer(perClientLimit()) + defer srv.Close() + summary := run(t, srv, true, spoofedipbypass.Check) + require.Len(t, summary.Observations, 1) + assert.Equal(t, "X-Forwarded-For", summary.Observations[0].Metadata["header"]) +} + +func TestSpoofedIPBypass_GlobalKey_NoFindings(t *testing.T) { + srv := httptest.NewServer(globalLimit()) + defer srv.Close() + assert.Empty(t, run(t, srv, true, spoofedipbypass.Check).Observations) +} + +func TestSpoofedIPBypass_NoThrottling_Skipped(t *testing.T) { + srv := httptest.NewServer(noLimit()) + defer srv.Close() + assert.True(t, skipped(run(t, srv, true, spoofedipbypass.Check), spoofedipbypass.Check.ID)) +} + +func TestOversizedHeader_Accepted_Flagged(t *testing.T) { + srv := httptest.NewServer(noLimit()) + defer srv.Close() + assert.Len(t, run(t, srv, true, oversizedheader.Check).Observations, 1) +} + +func TestOversizedHeader_Rejected_NoFindings(t *testing.T) { + srv := httptest.NewServer(rejectBigHeader()) + defer srv.Close() + assert.Empty(t, run(t, srv, true, oversizedheader.Check).Observations) +} + +func skipped(summary harnessx.ScanSummary, id harnessx.CheckID) bool { + for _, r := range summary.Results { + if r.CheckID == id { + return r.Skipped + } + } + return false +} diff --git a/proxy/checks/ratelimit/rlprobe/rlprobe.go b/proxy/checks/ratelimit/rlprobe/rlprobe.go new file mode 100644 index 0000000..72cb52e --- /dev/null +++ b/proxy/checks/ratelimit/rlprobe/rlprobe.go @@ -0,0 +1,76 @@ +// Package rlprobe holds the small request helpers the rate-limit checks +// share: a single GET that reports only its status, a bounded burst, and +// the predicate for a throttled response. Bursts are deliberately small so +// the probe measures throttling behaviour without approximating a flood. +package rlprobe + +import ( + "context" + "net/http" + + "github.com/cerberauth/proxyaudit/proxy/scanctx" +) + +// BurstSize is the number of requests a burst sends — enough to cross a +// modest per-IP limit, not enough to be a denial-of-service in itself. +const BurstSize = 20 + +// Throttled reports whether status is a rate-limit rejection. +func Throttled(status int) bool { + return status == http.StatusTooManyRequests || status == http.StatusServiceUnavailable +} + +// Get sends one GET to url with the given headers set and returns the +// response status code (0 on a transport error). +func Get(ctx context.Context, sctx *scanctx.ScanContext, url string, headers map[string]string) (int, error) { + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + if err != nil { + return 0, err + } + for k, v := range headers { + req.Header.Set(k, v) + } + // Don't follow redirects to another origin; the status of the proxy's + // own immediate response is what matters. + client := &http.Client{ + Transport: sctx.HTTPClient.Transport, + Timeout: sctx.HTTPClient.Timeout, + CheckRedirect: func(*http.Request, []*http.Request) error { + return http.ErrUseLastResponse + }, + } + resp, err := client.Do(req) + if err != nil { + return 0, err + } + _ = resp.Body.Close() + return resp.StatusCode, nil +} + +// Burst sends n sequential GETs to url and returns each status (0 for a +// transport error). It stops early once a throttled status appears, since +// callers only need to know whether and when throttling kicks in. +func Burst(ctx context.Context, sctx *scanctx.ScanContext, url string, n int) ([]int, error) { + statuses := make([]int, 0, n) + for range n { + status, err := Get(ctx, sctx, url, nil) + if err != nil { + return statuses, err + } + statuses = append(statuses, status) + if Throttled(status) { + break + } + } + return statuses, nil +} + +// AnyThrottled reports whether any status in the slice is a throttle. +func AnyThrottled(statuses []int) bool { + for _, s := range statuses { + if Throttled(s) { + return true + } + } + return false +} diff --git a/proxy/checks/ratelimit/spoofed_ip_bypass/check.go b/proxy/checks/ratelimit/spoofed_ip_bypass/check.go new file mode 100644 index 0000000..617b534 --- /dev/null +++ b/proxy/checks/ratelimit/spoofed_ip_bypass/check.go @@ -0,0 +1,89 @@ +// Package spoofedipbypass tests whether a proxy that does throttle keys its +// rate limit on a client-supplied header (X-Forwarded-For, X-Real-IP, ...) +// rather than the real transport peer. If it does, an attacker resets the +// limit at will by rotating a spoofed IP in that header, defeating the +// throttle entirely. +// +// It first drives a burst until the proxy throttles; if nothing throttles +// within the burst there is no limit to bypass and the check skips. Once +// throttled, it confirms a plain request is still being throttled, then +// sends a request carrying a fresh spoofed IP in each candidate header — +// a header that flips the response back to success is a confirmed bypass. +// +// Requires --aggressive: it sends a burst of requests, part of the opt-in +// attack-simulation suite. +package spoofedipbypass + +import ( + "context" + _ "embed" + "fmt" + "strconv" + + "github.com/cerberauth/harnessx" + "github.com/cerberauth/harnessx/checkdef" + "github.com/cerberauth/proxyaudit/proxy/checks/ratelimit/rlprobe" + "github.com/cerberauth/proxyaudit/proxy/probebase" + "github.com/cerberauth/proxyaudit/proxy/scanctx" +) + +//go:embed check.yaml +var checkYAML []byte + +var Def = checkdef.MustParseCheckDefYAML("spoofed_ip_bypass", checkYAML) + +// spoofHeaders are the client-IP headers a misconfigured proxy may use as +// the rate-limit key instead of the transport peer address. +var spoofHeaders = []string{"X-Forwarded-For", "X-Real-IP", "True-Client-IP", "X-Client-IP", "X-Forwarded"} + +// freshIP returns a distinct, routable-looking address for attempt n so +// each spoofed request looks like a different client. +func freshIP(n int) string { + return fmt.Sprintf("198.51.100.%d", 1+n%250) // TEST-NET-2, non-routable but valid +} + +var Check = checkdef.NewCheck(Def, func(ctx context.Context, target harnessx.Target, _ harnessx.ResultStore) (harnessx.Result, error) { + sctx := scanctx.TargetContext(target) + if !sctx.Aggressive { + return harnessx.Result{Skipped: true, SkipReason: "aggressive-suite check — rerun with --aggressive to send a rate-limit burst"}, nil + } + + // Drive the proxy into throttling first; a slightly larger burst than + // detection alone, to cross the limit reliably. + statuses, err := rlprobe.Burst(ctx, sctx, target.URL, rlprobe.BurstSize+10) + if err != nil { + return harnessx.Result{Err: err}, nil + } + if !rlprobe.AnyThrottled(statuses) { + return harnessx.Result{Skipped: true, SkipReason: "no throttling observed in a burst — no rate limit to bypass"}, nil + } + + for i, h := range spoofHeaders { + // Confirm the plain client is still throttled right now, so a + // success under the spoofed header is attributable to the header, + // not to the limit window having elapsed. + plain, err := rlprobe.Get(ctx, sctx, target.URL, nil) + if err != nil { + return harnessx.Result{Err: err}, nil + } + if !rlprobe.Throttled(plain) { + return harnessx.Result{Skipped: true, SkipReason: "throttle window elapsed before the bypass could be tested — rerun to retry"}, nil + } + + ip := freshIP(i) + spoofed, err := rlprobe.Get(ctx, sctx, target.URL, map[string]string{h: ip}) + if err != nil { + return harnessx.Result{Err: err}, nil + } + if rlprobe.Throttled(spoofed) || spoofed == 0 { + continue + } + return harnessx.Result{Observations: []harnessx.Observation{{ + Title: "Rate limit bypassed via spoofed " + h, + Description: "The proxy throttled a burst from this client (plain request still returns " + strconv.Itoa(plain) + "), but the same request carrying a spoofed " + h + ": " + ip + " was served normally (" + strconv.Itoa(spoofed) + "). The rate limit is keyed on the client-supplied " + h + " header rather than the real connection peer, so an attacker resets it at will by rotating that header — defeating the throttle.", + Evidence: "plain -> " + strconv.Itoa(plain) + "; " + h + ": " + ip + " -> " + strconv.Itoa(spoofed), + Metadata: map[string]string{"header": h, "plain_status": strconv.Itoa(plain), "spoofed_status": strconv.Itoa(spoofed)}, + }}}, nil + } + return harnessx.Result{}, nil +}, checkdef.WithSkip(probebase.SkipUnlessFetched)) diff --git a/proxy/checks/ratelimit/spoofed_ip_bypass/check.yaml b/proxy/checks/ratelimit/spoofed_ip_bypass/check.yaml new file mode 100644 index 0000000..48410fb --- /dev/null +++ b/proxy/checks/ratelimit/spoofed_ip_bypass/check.yaml @@ -0,0 +1,13 @@ +id: "ratelimit.spoofed_ip_bypass" +name: "Rate Limit Bypassed via Spoofed Client-IP Header" +description: "For a proxy that does throttle, tests whether the rate limit is keyed on a client-supplied header (X-Forwarded-For, X-Real-IP, True-Client-IP, X-Client-IP, X-Forwarded) rather than the real connection peer. It drives the proxy into throttling, confirms a plain request is still throttled, then flips the response back to success by rotating a spoofed IP in each header — a confirmed bypass. Skips when no throttling is observed. Requires --aggressive." +link: "https://portswigger.net/web-security/web-cache-deception" +tags: + - rate-limiting + - dos +depends_on: + - "probe.http_fetch" +cvss_vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N" +cvss_score: 6.9 +cwe_id: "CWE-770" +owasp: "API4:2023"