Runway 1.1.2

This commit is contained in:
Runway committed 2026-10-29 12:42:22 -06:00
1 parent 67d61f339c
commit 5fa0c1ef9f
29 files changed
+548 -76

No files matched your search

@@ -6,14 +6,16 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Set;
import mx.quest.runway.web.FilterOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.servlet.filter.OrderedFormContentFilter;
/**
* Spring Boot's {@code FormContentFilter}, minus plugin routes. Boot registers that filter outermost (order
* {@code -9900}) so a {@code PUT}/{@code PATCH}/{@code DELETE} form body becomes request parameters for
* Spring Boot's {@code FormContentFilter}, minus plugin routes. Boot registers that filter early (order
* {@code -9900}; Runway places it at {@link FilterOrder#CORE_FORM_CONTENT}, inside the access log and the site
* binding, so its {@code 413} is logged for the site) so a {@code PUT}/{@code PATCH}/{@code DELETE} form body becomes request parameters for
* {@code @RequestParam}; it does that by <b>reading the body</b>, so a plugin route used to receive an empty
* {@code RouteRequest.form()} and {@code body()} for those methods — and a {@code _csrf} field in such a body was not
* found either ({@code RouteBodyMethodsE2ETest}). A request whose method and path match a registered route
@@ -51,6 +53,7 @@ public class RouteAwareFormContentFilter extends OrderedFormContentFilter {
public RouteAwareFormContentFilter(ObjectProvider<EndpointContributorRegistry> registry, long cap) {
this.registry = registry;
this.cap = Math.max(0, cap);
setOrder(FilterOrder.CORE_FORM_CONTENT);
}
@Override
@@ -1,6 +1,5 @@
package mx.quest.runway.log;
import mx.quest.runway.site.SiteResolver;
import mx.quest.runway.web.FilterOrder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
@@ -8,19 +7,18 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Registers {@link AccessLogFilter} as the innermost filter ({@link FilterOrder#CORE_ACCESS_LOG}), so its
* post-phase observes the final response status of every public request, and enables {@link LogProperties}.
* Registers {@link AccessLogFilter} at {@link FilterOrder#CORE_ACCESS_LOG}, just inside the abuse floor, so it logs
* every public request the floor lets through with its final status, and enables {@link LogProperties}.
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(LogProperties.class)
public class AccessLogConfig {
@Bean
public FilterRegistrationBean<AccessLogFilter> accessLogFilterRegistration(SiteResolver siteResolver,
SiteLogService siteLog,
public FilterRegistrationBean<AccessLogFilter> accessLogFilterRegistration(SiteLogService siteLog,
LogProperties properties) {
FilterRegistrationBean<AccessLogFilter> registration = new FilterRegistrationBean<>(
new AccessLogFilter(siteResolver, siteLog, properties.isAccessLogUserAgent()));
new AccessLogFilter(siteLog, properties.isAccessLogUserAgent()));
registration.setOrder(FilterOrder.CORE_ACCESS_LOG);
registration.addUrlPatterns("/*");
registration.setName("accessLogFilter");
@@ -5,8 +5,7 @@ import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import mx.quest.runway.site.Site;
import mx.quest.runway.site.SiteResolver;
import mx.quest.runway.site.SiteContextFilter;
import mx.quest.runway.web.ClientIp;
import mx.quest.runway.web.LogSafe;
import mx.quest.runway.web.RequestPaths;
@@ -15,9 +14,16 @@ import org.slf4j.LoggerFactory;
import org.springframework.web.filter.OncePerRequestFilter;
/**
* The innermost filter ({@code FilterOrder.CORE_ACCESS_LOG}): it logs one event per <b>public</b> request from
* its {@code post} phase, so it observes the <b>final</b> status set by every inner filter and the handler.
* Being innermost is the whole point — an outer position would log a not-yet-decided status.
* The access log: one event per <b>public</b> request, written from its {@code post} phase, once every inner filter
* and the handler have finished, so the status it records is the one the request was answered with. (The exception:
* an exception escaping the chain, which only a plugin's own MVC controller can let through, is logged with the
* status set before it, while the container answers {@code 500}.) It sits at {@code FilterOrder.CORE_ACCESS_LOG}, just inside the abuse floor and outside every
* other filter, so it sees every request the floor lets through however it is answered: by a page, an endpoint
* route, Spring Security (a login attempt, a CSRF {@code 403}), a tenant gate (a suspended or over-quota site's
* {@code 503}), a refused slow body ({@code 408}) or an oversized form refused unread ({@code 413}). A filter that answers without calling the chain is invisible
* to every filter inside it, which is why this one is not innermost: there, until 1.1.2, a password-guessing run
* against a site's login left no line at all. Rejections by the floor itself are reported, throttled, by
* {@code EdgeRejectionRecorder} instead.
*
* <p>It is a <b>public-traffic</b> log, not an audit trail: it skips the internal surfaces (anything under
* {@code /__…} — the app/admin/preview/assets/CSP-report consoles — plus {@code /app/…} and {@code /actuator}),
@@ -25,29 +31,24 @@ import org.springframework.web.filter.OncePerRequestFilter;
* {@link ClientIp#of} (never a raw forwarded header).
*
* <p>It emits to two sinks: the operator's {@code runway.access} SLF4J logger (the whole-platform stream), and —
* when a site is bound (a public tenant request) — that site's own {@link SiteLogService#access per-site access
* log}. This filter runs <em>inside</em> the site-context filter, so the tenant binding is still live in the
* post phase.
* when a site answered (a public tenant request) — that site's own {@link SiteLogService#access per-site access
* log}. The site is read from the {@link SiteContextFilter#SITE_ID_ATTRIBUTE request attribute} the site-context
* filter leaves, not from {@code SiteResolver.current()}: that filter is inner of this one and has cleared its
* thread binding by the time this {@code post} runs. A request refused before the site is resolved has no site and
* goes to the platform log only.
*/
public class AccessLogFilter extends OncePerRequestFilter {
private static final Logger log = LoggerFactory.getLogger("runway.access");
private final SiteResolver siteResolver;
private final SiteLogService siteLog;
private final boolean logUserAgent;
public AccessLogFilter(SiteResolver siteResolver, SiteLogService siteLog, boolean logUserAgent) {
this.siteResolver = siteResolver;
public AccessLogFilter(SiteLogService siteLog, boolean logUserAgent) {
this.siteLog = siteLog;
this.logUserAgent = logUserAgent;
}
/** Pre-{@code logUserAgent} form, kept so existing call sites (and tests) compile unchanged: agent off. */
public AccessLogFilter(SiteResolver siteResolver, SiteLogService siteLog) {
this(siteResolver, siteLog, false);
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
@@ -69,9 +70,8 @@ public class AccessLogFilter extends OncePerRequestFilter {
log.info("{} {} {} -> {} ({}ms)", ip, request.getMethod(),
request.getRequestURI(), response.getStatus(), millis);
}
Site site = siteResolver.current().orElse(null);
if (site != null) {
siteLog.access(site.id(), ip, request.getMethod(), request.getRequestURI(), response.getStatus());
if (request.getAttribute(SiteContextFilter.SITE_ID_ATTRIBUTE) instanceof String siteId) {
siteLog.access(siteId, ip, request.getMethod(), request.getRequestURI(), response.getStatus());
}
}
}
@@ -62,6 +62,14 @@ public class SiteLogService {
private final SiteLogConfigService configs;
private final LogProperties props;
private final BlockingQueue<LogEvent> queue;
/**
* Queue slots only audit events may take. Access and audit lines share the queue, and a flood that gets past the
* protection edge (a credential-stuffing run, two events per attempt) would otherwise drop audit lines, the
* {@code login.failure} records that are the evidence of that very attack, as often as access lines. With an
* eighth of the queue held back, access lines are dropped first.
*/
private final int auditReserve;
static final int AUDIT_RESERVE_DIVISOR = 8;
private final AtomicLong dropped = new AtomicLong();
private static final long DROP_WARN_INTERVAL_MS = 60_000L;
private volatile long lastDropWarnAt;
@@ -73,7 +81,9 @@ public class SiteLogService {
this.layout = layout;
this.configs = configs;
this.props = props;
this.queue = new ArrayBlockingQueue<>(Math.max(16, props.getQueueCapacity()));
int capacity = Math.max(16, props.getQueueCapacity());
this.queue = new ArrayBlockingQueue<>(capacity);
this.auditReserve = capacity / AUDIT_RESERVE_DIVISOR;
}
@PostConstruct
@@ -113,6 +123,16 @@ public class SiteLogService {
List.of(clean(actor), clean(action), clean(detail))));
}
/** Accepts events without starting the writer, so a test can fill the queue. */
void acceptWithoutWriting() {
running = true;
}
/** Events waiting to be written (tests). */
int queued() {
return queue.size();
}
/** The number of events dropped because the queue was full (best-effort observability). */
public long droppedCount() {
return dropped.get();
@@ -219,7 +239,9 @@ public class SiteLogService {
if (!running) {
return;
}
if (!queue.offer(event)) {
boolean accepted = event.kind() == LogKind.ACCESS && queue.remainingCapacity() <= auditReserve
? false : queue.offer(event);
if (!accepted) {
long total = dropped.incrementAndGet();
// A saturated queue silently losing events (audit lines included) is exactly what an operator needs
// told — but the drop path must stay non-blocking and un-spammy, so warn at most once a minute.
@@ -15,9 +15,9 @@ import org.slf4j.LoggerFactory;
* <h2>The blind spot this closes</h2>
* {@link EdgeRejectFilter} sits at {@code FilterOrder.CORE_PROTECTION}, the outermost slot after the forwarded
* header gate, and a reject <b>does not call the chain</b>. {@code AccessLogFilter} sits at
* {@code CORE_ACCESS_LOG}, the innermost. So every edge {@code 403}/{@code 429} short-circuits <i>before</i>
* anything logs it: the request appears in no log anywhere in the product, and the access log never carried a
* {@code User-Agent} to begin with. The practical result was that nobody could answer either half of the
* {@code CORE_ACCESS_LOG}, inside the floor (on purpose: see the throttling below). So every edge
* {@code 403}/{@code 429} short-circuits <i>before</i> anything logs it: without this recorder the request
* appears in no log anywhere in the product, and the access log carries a {@code User-Agent} only when asked to. The practical result was that nobody could answer either half of the
* obvious question — <i>was a crawler throttled</i>, and <i>why was this request rejected</i>.
*
* <p>A rejection is also emitted <b>before</b> {@code CORE_SITE_CONTEXT}, so there is no resolved site and it
@@ -20,6 +20,7 @@ import org.springframework.core.Ordered;
* <pre>
* CORE_FORWARDED Integer.MIN_VALUE EDGE_INGRESS TrustedForwardedHeaderFilter (gates X-Forwarded-*)
* CORE_PROTECTION MIN_VALUE + 1 EDGE_INGRESS EdgeRejectFilter (the O(1) reject seam)
* CORE_ACCESS_LOG -500 (own slot) AccessLogFilter (one line per request past the floor)
* CORE_BANDWIDTH -300 EDGE_EGRESS BandwidthFilter (meters the on-the-wire bytes)
* CORE_SITE_METRICS -290 EDGE_EGRESS SiteRequestMetricsFilter (per-site request timing)
* CORE_COMPRESSION -200 EDGE_EGRESS CompressionFilter (brotli / gzip, one decision)
@@ -30,13 +31,13 @@ import org.springframework.core.Ordered;
* CORE_SITE_RELOAD 56 TENANT SiteReloadFilter (loopback /__reload/**)
* CORE_CONSOLE_HOST 57 TENANT ConsoleHostFilter (operator console off site hosts)
* CORE_ROUTE_FORM_CAPTURE 58 TENANT RouteFormCaptureFilter (reads a plugin route's form body)
* CORE_FORM_CONTENT 59 TENANT RouteAwareFormContentFilter (PUT/PATCH/DELETE forms)
* CORE_SUSPENDED_SITE 60 TENANT SuspendedSiteFilter (503s a suspended tenant)
* CORE_QUARANTINED_SITE 65 TENANT QuarantinedSiteFilter (503s a quarantined admin)
* CORE_MAINTENANCE 68 TENANT MaintenanceSiteFilter (503s a self-maintenance tenant)
* CORE_BANDWIDTH_LIMIT 69 TENANT BandwidthLimitFilter (503s a tenant over its quota)
* CORE_EDGE_MODE 70 TENANT (reserved — read-only edge/replica topology, later)
* CORE_SECURITY 100 SECURITY the Spring Security FilterChainProxy
* CORE_ACCESS_LOG Integer.MAX_VALUE innermost AccessLogFilter (final status, post-chain)
* </pre>
*
* <h2>Why these values</h2>
@@ -197,13 +198,33 @@ public final class FilterOrder {
/**
* The kernel route dispatcher for {@code EndpointContributor} routes (robots.txt, sitemap, …) — a terminal
* application handler, inner of the plugin APPLICATION window so a plugin filter can still wrap it. It
* short-circuits a matched route, so such responses are not seen by the (inner) access log — endpoint/bot
* traffic is a separate category from the public page access log.
* short-circuits a matched route; the access log, far outside it, still records the answer.
*/
public static final int CORE_ENDPOINT_DISPATCH = Integer.MAX_VALUE - 100;
/** {@code AccessLogFilter} — innermost, so its post observes the final status after every inner filter. */
public static final int CORE_ACCESS_LOG = Ordered.LOWEST_PRECEDENCE;
/**
* {@code AccessLogFilter} — inner of the whole EDGE_INGRESS band (the kernel's reject floor and any plugin
* ingress filter) and outer of everything else, so every request that gets past the abuse floor is logged,
* whoever answers it: a tenant gate's {@code 503}, Spring Security (a login attempt, a CSRF {@code 403}), a
* slow body's {@code 408}, an endpoint route, a page. Its {@code post} runs after every inner filter has
* returned, so the status it reads is final.
*
* <p>Until 1.1.2 it sat innermost ({@code Integer.MAX_VALUE}), and every filter that answered without calling
* the chain answered unseen: a password-guessing run against a site's {@code /login} left no line at all.
* Floor rejections stay out on purpose: a flood the floor turns away in O(1) must not become a flood of log
* writes; {@code EdgeRejectionRecorder} reports them, throttled, under {@code runway.protect}.
*/
public static final int CORE_ACCESS_LOG = -500;
/**
* {@code RouteAwareFormContentFilter} (Boot's {@code FormContentFilter}, which parses a {@code PUT}/{@code PATCH}/
* {@code DELETE} form body into parameters, bounded). Boot's own order is {@code -9900}, outer of the access log,
* where its {@code 413} for an oversized body went unlogged. Here it is inner of the site binding, so the refusal
* is in that site's log too, and inner of {@link #CORE_ROUTE_FORM_CAPTURE}, which must read a route's body
* first; and outer of the tenant gates, every plugin TENANT filter and the security chain, which read
* parameters (the CSRF check above all).
*/
public static final int CORE_FORM_CONTENT = 59;
private FilterOrder() {
}