Fix SignatureParser accepting duplicate parameters in HTTP Signature header (#37375)

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Shlee 2026-01-08 17:47:53 +07:00 committed by Claire
parent 1eb8d1b967
commit adea0b7b31

View file

@ -25,9 +25,13 @@ class SignatureParser
# Use `skip` instead of `scan` as we only care about the subgroups
while scanner.skip(PARAM_RE)
key = scanner[:key]
# Detect a duplicate key
raise Mastodon::SignatureVerificationError, 'Error parsing signature with duplicate keys' if params.key?(key)
# This is not actually correct with regards to quoted pairs, but it's consistent
# with our previous implementation, and good enough in practice.
params[scanner[:key]] = scanner[:value] || scanner[:quoted_value][1...-1]
params[key] = scanner[:value] || scanner[:quoted_value][1...-1]
scanner.skip(/\s*/)
return params if scanner.eos?