Description
The core HTTP binding uses urllib.parse.unquote() with its default errors="replace". As a result, an invalid percent-encoded UTF-8 attribute such as ce-subject: %FF is accepted and silently changed to the replacement character.
The HTTP binding specification section 3.1.3.2 requires rejecting encoded byte sequences that are invalid UTF-8: https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/bindings/http-protocol-binding.md#3132-http-header-values
Reproduction on main:
from cloudevents.core.bindings.http import HTTPMessage, from_binary
from cloudevents.core.formats.json import JSONFormat
event = from_binary(HTTPMessage(
headers={"ce-specversion":"1.0", "ce-id":"123", "ce-type":"test",
"ce-source":"/example", "ce-subject":"%FF"},
body=b"",
), JSONFormat())
print(repr(event.get_attributes()["subject"])) # '\ufffd'The same happens through from_http. This should raise a decoding error. Valid UTF-8, unnecessarily encoded ASCII, and literal plus signs should retain their existing behavior. This concerns validation in the existing decoder; it does not change which values the sender percent-encodes.
Activity