Skip to content

fix(brotli): don't log expected non-standard ETag at error level#13545

Open
AlinsRan wants to merge 1 commit into
apache:masterfrom
AlinsRan:fix/brotli-etag-handling
Open

fix(brotli): don't log expected non-standard ETag at error level#13545
AlinsRan wants to merge 1 commit into
apache:masterfrom
AlinsRan:fix/brotli-etag-handling

Conversation

@AlinsRan

@AlinsRan AlinsRan commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

TL;DR

brotli.lua logged an expected non-quoted upstream ETag at error level (printing ... : nil), spamming the error log.

Cause

weak_etag_header() downgrades a strong ETag to a weak one (Brotli alters the body, so a strong validator no longer holds). When the upstream ETag is not a quoted string the regex simply does not match — an expected case — but the code logs it at error level with a nil err:

local matched, err = ngx.re.match(etag, regex, "jo")
if not matched or err then
    core.response.set_header("Etag", nil)
    core.log.error("no standard etag or regex match failed: ", err)  -- err is nil here
    return
end

Fix

  • Only log at error level when ngx.re.match actually returns an error; otherwise drop the ETag silently (behavior unchanged).
  • Tighten the capture group from (.*) to ([^"]*) so a malformed ETag containing internal quotes is treated as non-standard (and dropped) rather than weakened into another malformed value.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change (N/A)
  • I have verified that the changes pass the existing tests

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Jun 12, 2026
weak_etag_header() logged `core.log.error("no standard etag or regex match
failed: ", err)` whenever the upstream ETag was not a quoted string, even
though that is an expected case (err is nil) — producing error-level noise
on every such response. Only log at error level when ngx.re.match actually
returns an error, and drop the ETag silently otherwise. Also tighten the
capture from (.*) to ([^"]*) so a malformed ETag with internal quotes is
treated as non-standard rather than weakened.

Signed-off-by: AlinsRan <alinsran@apache.org>
@AlinsRan AlinsRan force-pushed the fix/brotli-etag-handling branch from aa03816 to 65c9907 Compare June 12, 2026 06:39
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant