Skip to content

fix(http): reject invalid UTF-8 in encoded attributes - #310

Open
zhanghao0806 wants to merge 1 commit into
cloudevents:mainfrom
zhanghao0806:fix/http-reject-invalid-utf8
Open

zhanghao0806 wants to merge 1 commit into
cloudevents:mainfrom
zhanghao0806:fix/http-reject-invalid-utf8

Conversation

@zhanghao0806

Copy link
Copy Markdown
Contributor

Description

Decode percent-encoded HTTP CloudEvents attributes with strict UTF-8 validation. unquote() previously substituted replacement characters for malformed byte sequences, silently changing attribute values. The HTTP binding requires those sequences to be rejected.

Fixes #307. Specification: https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/bindings/http-protocol-binding.md#3132-http-header-values

Validation

  • Before the fix: 8 new regression cases failed through from_binary and from_http.
  • Full pytest -q: 887 passed, 18 xfailed.
  • Ruff lint/format, source MyPy, and git diff --check: passed.
  • Covers invalid leading bytes, continuation bytes, encoded surrogates, and truncated multibyte sequences, plus valid Unicode, unnecessarily encoded ASCII, and literal +.

The sender's encoding policy is unchanged. Prepared with AI assistance; commits are signed off.

Signed-off-by: zhanghao <112082360+zhanghao0806@users.noreply.github.com>

@PlugaruT PlugaruT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Core HTTP decoder silently replaces invalid percent-encoded UTF-8

2 participants