waf: one Cookie line, and a 500 ms GeoJS wait (closes #401)
check / check (push) Failing after 14m7s
check / check (push) Failing after 14m7s
A browser sends all its cookies on one Cookie line (RFC 6265), and Go's server joins HTTP/2 Cookie lines into one, so waf now refuses a second line with 431. Further lines only gave a visitor more bytes for the Core Rule Set to read. The refusal logs cookie_lines and cookie_lines_limit. The default of SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS drops from 800 to 500 milliseconds, so the Core Rule Set's share of rproxy's 2 seconds grows from 1 to 1.3 seconds. The slowest worst-case request takes about 0.84 seconds of processor time with every core busy. Model: opus-5-5
This commit is contained in:
1 parent
988f117ef3
commit
01a8a7aa08
9 files changed
+68
-47
No files matched your search
@@ -10,11 +10,15 @@ import (
|
||||
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
||||
)
|
||||
|
||||
// The header limits: the most cookies and header fields a request may have,
|
||||
// and the longest its request line and each header line may be, in bytes, not
|
||||
// counting the line ending. Real clients rarely reach them. maxLineBytes is
|
||||
// what nginx allows by default.
|
||||
// The header limits: the most Cookie lines, cookies and header fields a request
|
||||
// may have, and the longest its request line and each header line may be, in
|
||||
// bytes, not counting the line ending. Real clients rarely reach them.
|
||||
// maxLineBytes is what nginx allows by default. A browser sends all its cookies
|
||||
// on one Cookie line, as RFC 6265 requires, and Go's server joins the Cookie
|
||||
// lines of an HTTP/2 request into one. A second line would only give a visitor
|
||||
// another 8 KiB for the Core Rule Set to read.
|
||||
const (
|
||||
maxCookieLines = 1
|
||||
maxCookies = 50
|
||||
maxHeaderFields = 100
|
||||
maxLineBytes = 8 << 10
|
||||
@@ -22,10 +26,11 @@ const (
|
||||
|
||||
// headerLimits refuses a request with a request line longer than maxLineBytes,
|
||||
// with 414. It refuses a request with a header line longer than maxLineBytes,
|
||||
// more than maxHeaderFields header fields or more than maxCookies cookies, with
|
||||
// 431. Its figures are the request line's length and its limit for 414. For
|
||||
// 431 they are the longest header line, the header fields and the cookies,
|
||||
// each with its limit.
|
||||
// more than maxHeaderFields header fields, more than maxCookieLines Cookie
|
||||
// lines or more than maxCookies cookies, with 431. Its figures are the request
|
||||
// line's length and its limit for 414. For 431 they are the longest header
|
||||
// line, the header fields, the Cookie lines and the cookies, each with its
|
||||
// limit.
|
||||
type headerLimits struct{}
|
||||
|
||||
func (headerLimits) name() string { return "header_limits" }
|
||||
@@ -48,9 +53,10 @@ func (headerLimits) check(
|
||||
|
||||
longest := rq.longestHeaderLineBytes()
|
||||
fields, cookies := rq.headerCounts()
|
||||
cookieLines := len(rq.in.Header.Values("Cookie"))
|
||||
|
||||
if longest <= maxLineBytes && fields <= maxHeaderFields &&
|
||||
cookies <= maxCookies {
|
||||
cookieLines <= maxCookieLines && cookies <= maxCookies {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -60,6 +66,7 @@ func (headerLimits) check(
|
||||
"longest_header_line_bytes": longest,
|
||||
"header_line_bytes_limit": maxLineBytes,
|
||||
"fields": fields, "fields_limit": maxHeaderFields,
|
||||
"cookie_lines": cookieLines, "cookie_lines_limit": maxCookieLines,
|
||||
"cookies": cookies, "cookies_limit": maxCookies,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user