Skip to content
Open
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
11 changes: 7 additions & 4 deletions apisix/plugins/brotli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,15 @@ local function weak_etag_header()
return
end

local regex = [[^(W/)?"(.*)"$]]
local regex = [[^(W/)?"([^"]*)"$]]
local matched, err = ngx.re.match(etag, regex, "jo")
if not matched or err then
-- not standard etag, no quote
if err then
core.log.error("failed to match etag: ", err)
end
if not matched then
-- non-standard etag (not quoted) or a match failure; it cannot be
-- weakened, so drop it
core.response.set_header("Etag", nil)
core.log.error("no standard etag or regex match failed: ", err)
return
end

Expand Down
23 changes: 21 additions & 2 deletions t/plugin/brotli.t
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,8 @@ Content-Encoding: br
Vary:
Etag:
Content-Length:
--- error_log
no standard etag or regex match failed:
--- no_error_log
[error]



Expand Down Expand Up @@ -888,3 +888,22 @@ Vary:
Etag: W/"123456789"
Last-Modified: Thu, 27 Nov 2025 00:32:33 GMT
Content-Length:



=== TEST 37: etag with embedded quotes is non-standard, clear it
--- request
POST /echo
0123456789
012345678
--- more_headers
Accept-Encoding: br
Content-Type: text/html
Etag: "12"34"
--- response_headers
Content-Encoding: br
Vary:
Etag:
Content-Length:
--- no_error_log
[error]
Loading