Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -344,26 +344,28 @@ public static final class WARN {
.build();

/**
* The accept-time SNI front closed a connection at once, for one of exactly three reasons. At
* accept, without reading from it: the undecided-connection cap was full ({@code cap}), or the
* connection's source already held its full share of that cap ({@code source_share}). At the
* route decision of a passthrough match, without dialling its backend: the connection's target
* already had its full dial budget in flight ({@code dial_budget}), so the bound logged is that
* budget — the dialling connections of one target, which count against the cap. The cap and the
* share count connections waiting for their ClientHello or for their relay's backend dial to
* settle, so they fill under a flood of slow or silent handshakes and equally behind passthrough
* backends that do not answer the dial, whose connections each hold a slot for any host-name
* lookup of the backend plus the full connect timeout; the dial budget keeps one such backend
* from holding more than its eighth of the cap. Rate-limited: emitted at
* most once per fixed window per reason; every further refusal for that reason inside the window is a
* {@code DEBUG} diagnostic, and every refusal is counted on
* {@code sheriff_front_connections_refused_total}. Records the reason token, the bound that was
* full and the window in seconds only — never the peer address or any byte received.
* The accept-time SNI front closed a connection at once, for the
* {@link de.cuioss.sheriff.gateway.tls.SniFrontListener.Refusal reason} the record names, at the
* stage that reason refuses at. The parameters are the reason's
* {@link de.cuioss.sheriff.gateway.tls.SniFrontListener.Refusal#token() token}, its
* {@link de.cuioss.sheriff.gateway.tls.SniFrontListener.Refusal#stage() stage}, the bound that was
* full and the window in seconds. The template names no reason and no stage of its own: both
* come from the refusal being logged, so a reason added to the enum is logged truthfully without
* the template changing. The reasons, their stages and the bound each one reports are documented
* on the enum. The bounds count connections waiting for their ClientHello or for their relay's
* backend dial to settle, so they fill under a flood of slow or silent handshakes and equally
* behind passthrough backends that do not answer the dial, whose connections each hold a slot for
* any host-name lookup of the backend plus the full connect timeout. Rate-limited: emitted at most
* once per fixed window per reason; every further
* refusal for that reason inside the window is a {@code DEBUG} diagnostic, and every refusal is
* counted on {@code sheriff_front_connections_refused_total}. Records the reason token, its stage,
* the bound that was full and the window in seconds only — never the peer address or any byte
* received.
*/
public static final LogRecord FRONT_CONNECTION_REFUSED = LogRecordModel.builder()
.prefix(PREFIX)
.identifier(146)
.template("Front connection refused at accept (%s): the bound of %s undecided connections is full — further refusals for this reason within %s seconds stay at DEBUG and are counted on sheriff_front_connections_refused_total")
.template("Front connection refused (%s) %s: a bound of %s connections is full — further refusals for this reason within %s seconds stay at DEBUG and are counted on sheriff_front_connections_refused_total")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@
* or widen it, and the step-up path is a {@code GET} that carries no CSRF check — but the conditions a
* compression oracle needs are absent:
* <ul>
* <li>the only attacker influence on the plaintext is which operator-declared, identity-provider-granted
* scope names enter it; no byte of any field comes from a request;</li>
* <li>every re-seal carries the freshly issued tokens of the refresh or widening that caused it, so
* no two seals compress the same token;</li>
* <li>the material that stays the same across re-seals has no attacker-varied byte next to it, so it
* cannot be probed;</li>
* <li>the distinct plaintexts an attacker can cause are bounded by monotone scope growth — a
* widening only adds declared names — not by the number of requests it sends;</li>
* <li>the only attacker influence on the plaintext is which scope names the identity provider returns
* to a refresh or widening the attacker drives; no byte of any field comes from a request;</li>
* <li>every re-seal carries the freshly issued access token of the refresh or widening that caused it,
* so each seal compresses an access token no earlier seal carried;</li>
* <li>the material that stays the same across re-seals — the session nonce, and the ID token, which a
* refresh response without one leaves as it was, so two seals can compress the same ID token — has
* no attacker-varied byte next to it, so it cannot be probed;</li>
* <li>the distinct plaintexts an attacker can cause are bounded by the scope names the identity
* provider returns — a refresh replaces the active scope set with the response's scope, so the set
* can shrink as well as grow, and a widening adds the names the identity provider grants — not by
* the number of requests it sends;</li>
* <li>reading the sealed length needs an on-path observer of the cookie size; the cross-site page
* that drives a re-seal cannot read the gateway's {@code Set-Cookie} header.</li>
* </ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,11 @@ public void enforce(PipelineRequest request) {
* {@code Sec-Fetch-Mode} with it (and {@code Sec-Fetch-Dest} in every current version); a client
* that omits them is not a browser forged into the request and holds no victim's cookie.
* <p>
* {@code Sec-Fetch-Site: none} is not a proof. A browser sends it for a typed URL and a bookmark, but
* also for a link opened from another application — a mail client or a chat — so a delivered link
* carries it too. Such a request is answered the confirmation page by the caller, as is a request
* from a browser without Fetch Metadata and without {@code Origin}. A cookie-forwarding instance
* With {@code Origin} absent, {@code Sec-Fetch-Site: none} is not a proof; a trusted {@code Origin} is
* admitted whatever {@code Sec-Fetch-Site} says. A browser sends {@code none} for a typed URL and a
* bookmark, but also for a link opened from another application — a mail client or a chat — so a
* delivered link carries it too. Such a request is answered the confirmation page by the caller, as
* is a request from a browser without Fetch Metadata and without {@code Origin}. A cookie-forwarding instance
* has no received origin to compare against here, so only its additional origins are trusted.
* <p>
* Thread-safe: the defence is immutable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,10 @@ public static final class WARN {
* terminated listener ({@code quarkus.http.limits.max-connections}), so the connection cap no longer
* leaves the headroom the shipped values keep.
* <p>
* On HTTP/1.1 one request needs one connection, and the connection cap also counts every connection
* that carries no admitted request — an idle keep-alive connection, one whose request head has not
* arrived, one being answered {@code 503}. The shipped connection cap is twice the default admission
* On HTTP/1.1 one request needs one connection, and the connection cap also counts every established
* connection that carries no admitted request — an idle keep-alive connection, one that completed its
* TLS handshake but whose request head has not arrived, one being answered {@code 503}; a connection
* still in its TLS handshake is not counted yet. The shipped connection cap is twice the default admission
* cap, so admission refuses a request with a {@code 503} long before the cap closes connections,
* unserved and without a {@code 503}. An admission cap above half the connection cap gives that
* headroom up, and at or above the connection cap the cap rather than the admission budget bounds the
Expand Down Expand Up @@ -686,6 +687,31 @@ public static final class WARN {
.identifier(149)
.template("enumeration_detection.action is %s while forwarded.trusted_proxies is non-empty — a request a trusted proxy forwards without a Forwarded or X-Forwarded-For header, or with only blank ones, is keyed on the shared source 'unknown', which detection counts and reports but never blocks, delays or refuses, so such requests escape the configured action. Make sure every trusted proxy sends its clients' addresses in X-Forwarded-For")
.build();

/**
* {@code tls.passthrough_sni} is non-empty while the configuration treats the loopback relay leg
* as a client: {@code enumeration_detection} is enabled with the acting action {@code block} or
* {@code delay}, or a {@code forwarded.trusted_proxies} range holds a loopback address.
* <p>
* Behind the SNI front every terminated connection reaches the edge from the loopback relay leg,
* so source detection and the trusted-proxy judgement see every terminated client as that one
* loopback peer. An acting detection action therefore keys all of them on one source, and the
* block or delay that source earns acts on every terminated client at once; a loopback trusted
* proxy trusts every terminated client's own {@code Forwarded} and {@code X-Forwarded-For}
* headers.
* <p>
* It is a {@code WARN} and never a boot refusal: each combination is a legal configuration whose
* consequence the operator must know. Emitted by the validation rule
* {@code EdgeRules.validatePassthroughSourceCollapse}, once per present combination and per
* validation of the configuration: at boot, and in a {@code --validate-config} run. The template
* argument is a fixed token naming the combination — the action, or a loopback trusted proxy —
* never a configured range or any other address.
*/
public static final LogRecord PASSTHROUGH_SOURCE_COLLAPSE = LogRecordModel.builder()
.prefix(PREFIX)
.identifier(152)
.template("tls.passthrough_sni is non-empty while %s — behind the SNI front every terminated connection reaches the edge from the loopback relay leg, so source detection and the trusted-proxy judgement see every terminated client as that one loopback peer: an acting detection action blocks or delays all of them at once, and a loopback trusted proxy trusts every client's own forwarded headers. For the combination named here, set enumeration_detection.action to observe, or remove the loopback range from forwarded.trusted_proxies")
.build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
* {@link AnchorRules} (the anchors), {@link AuthRules} (the {@code auth} blocks and endpoint scopes),
* {@link LimitRules} (the security-filter profile, the edge limits, the enumeration detection, the
* threat classification and the unenforced {@code rate_limit}), {@link TerminalActionRules}
* (upstream, asset or redirect), {@link EdgeRules} (forwarded trust and TLS passthrough),
* (upstream, asset or redirect), {@link EdgeRules} (forwarded trust and TLS passthrough, including the
* boot WARN for a passthrough topology meeting an acting detection action or a loopback trusted proxy),
* {@link HeaderRules} (CORS, Content-Security-Policy and the security-header modes),
* {@link OidcSessionRules} (the BFF session), {@link OidcClientRules} (the OIDC client),
* {@link ReservedPathRules} (the reserved OIDC endpoint paths), {@link ProtocolRules} (WebSocket and
Expand Down Expand Up @@ -274,6 +275,7 @@ public final class ConfigValidator {
errors),
(gateway, endpoints, topology, errors) -> EdgeRules.validatePassthroughAliasResolvable(gateway, topology,
errors),
(gateway, endpoints, topology, errors) -> EdgeRules.validatePassthroughSourceCollapse(gateway),
(gateway, endpoints, topology, errors) -> ProtocolRules.validateWebSocketConfig(gateway, endpoints, errors),
(gateway, endpoints, topology, errors) -> ProtocolRules.validateRewriteLocationProtocol(endpoints, errors),
(gateway, endpoints, topology, errors) -> TerminalActionRules.validateAssetIndexAndFallback(endpoints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@
* {@code match.host} is a {@code tls.passthrough_sni} host, since such a host is relayed at L4 and the
* route would never be selected. The passthrough alias rule
* ({@link #validatePassthroughAliasResolvable}) requires every {@code passthrough_sni} alias to resolve
* in the topology to an origin carrying no base path.
* in the topology to an origin carrying no base path. The passthrough source-collapse rule
* ({@link #validatePassthroughSourceCollapse}) refuses nothing: it emits
* {@link ConfigLogMessages.WARN#PASSTHROUGH_SOURCE_COLLAPSE} when a non-empty {@code passthrough_sni}
* meets an acting {@code enumeration_detection} action or a loopback {@code trusted_proxies} range,
* since behind the SNI front every terminated client reaches the edge from the loopback relay leg.
* <p>
* Every rule appends file- and pointer-annotated {@link ConfigError}s to the shared list and never
* fails fast. Stateless, and free of framework dependencies as the pre-boot rule requires of this
Expand All @@ -80,6 +84,14 @@ public class EdgeRules {
private static final int BROAD_PREFIX_IPV4 = 16;
private static final int BROAD_PREFIX_IPV6 = 48;

/** The IPv4 loopback block, {@code 127.0.0.0/8}. */
private static final CidrRange IPV4_LOOPBACK = new CidrRange("127.0.0.0/8", IPV4_BITS, 8,
BigInteger.valueOf(0x7F00_0000L), BigInteger.valueOf(0x7FFF_FFFFL));

/** The IPv6 loopback address, {@code ::1/128}. */
private static final CidrRange IPV6_LOOPBACK = new CidrRange("::1/128", IPV6_BITS, IPV6_BITS,
BigInteger.ONE, BigInteger.ONE);

/**
* Rule: every {@code trusted_proxies} entry is a well-formed CIDR; the union of
* the parsed ranges per address family must not cover the entire IPv4 or IPv6
Expand Down Expand Up @@ -310,6 +322,59 @@ public static void validatePassthroughAliasResolvable(GatewayConfig gateway, Res
}
}

/**
* Rule: under a non-empty {@code tls.passthrough_sni}, emits the boot WARN
* {@link ConfigLogMessages.WARN#PASSTHROUGH_SOURCE_COLLAPSE} once for each configuration that acts
* on the loopback relay leg as if it were a client. Behind the SNI front every terminated connection
* reaches the edge from that one loopback leg, so the edge sees every terminated client as one
* loopback peer:
* <ul>
* <li>{@code enumeration_detection} enabled with the acting action {@code block} or {@code delay}
* keys every terminated client on that one source, so the action a source earns acts on all of them
* at once;</li>
* <li>a {@code forwarded.trusted_proxies} range holding a loopback address ({@code 127.0.0.0/8} or
* {@code ::1}) makes that leg a trusted proxy, so every client's own forwarded headers are
* trusted.</li>
* </ul>
* Without passthrough the rule returns at once. A malformed {@code trusted_proxies} entry is skipped
* here, because {@link #validateForwardedTrust} already refuses it. The record names the combination
* by a fixed token only — the action, or a loopback trusted proxy — never a configured range or
* address. It never refuses: each combination is a legal configuration whose consequence the
* operator must know.
*
* @param gateway the bound gateway document, whose {@code tls.passthrough_sni},
* {@code enumeration_detection} and {@code forwarded.trusted_proxies} are judged
*/
public static void validatePassthroughSourceCollapse(GatewayConfig gateway) {
if (passthroughSni(gateway).isEmpty()) {
return;
}
EnumerationDetectionConfig detection = gateway.enumerationDetection();
if (detection != null && detection.effectiveEnabled()
&& detection.effectiveAction() != EnumerationDetectionConfig.Action.OBSERVE) {
String actingAction = "enumeration_detection.action is " + detection.effectiveAction();
LOGGER.warn(ConfigLogMessages.WARN.PASSTHROUGH_SOURCE_COLLAPSE, actingAction);
}
ForwardedConfig forwarded = gateway.forwarded();
if (forwarded != null && forwarded.trustedProxies().stream().anyMatch(EdgeRules::holdsLoopback)) {
LOGGER.warn(ConfigLogMessages.WARN.PASSTHROUGH_SOURCE_COLLAPSE,
"forwarded.trusted_proxies holds a loopback range");
}
}

/**
* Whether a {@code trusted_proxies} entry holds a loopback address: an IPv4 range overlapping
* {@code 127.0.0.0/8}, or an IPv6 range containing {@code ::1}. A malformed entry holds none.
*/
private static boolean holdsLoopback(String cidr) {
return parseCidr(cidr).map(range -> overlaps(range, range.bits() == IPV4_BITS ? IPV4_LOOPBACK : IPV6_LOOPBACK))
.orElse(false);
}

private static boolean overlaps(CidrRange range, CidrRange other) {
return range.start().compareTo(other.end()) <= 0 && range.end().compareTo(other.start()) >= 0;
}

private static Map<String, String> passthroughSni(GatewayConfig gateway) {
TlsConfig tls = gateway.tls();
return tls == null ? Map.of() : tls.passthroughSni();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
* <strong>What the audit protects against.</strong> The connection cap
* ({@code quarkus.http.limits.max-connections}) is a fixed deployment value, not a {@code gateway.yaml}
* key, while the admission cap is configurable and has no schema maximum. On HTTP/1.1 one request needs
* one connection, and the cap also counts every connection that carries no admitted request — an idle
* keep-alive connection, one whose request head has not arrived, one being answered {@code 503}. The
* one connection, and the cap also counts every established connection that carries no admitted request —
* an idle keep-alive connection, one that completed its TLS handshake but whose request head has not
* arrived, one being answered {@code 503}; a connection still in its TLS handshake is not counted yet. The
* shipped connection cap is twice the default admission cap for that reason. An admission cap that gives
* that headroom up lets the cap close connections, unserved and without a {@code 503}, before admission
* refuses a request; at or above the connection cap the admission cap is never reached at all. Without
Expand Down
Loading