Skip to content

fix(1.x): verify the signature before reading the response (1.2.3) - #65

Merged
ddiazpinto merged 2 commits into
release/1.xfrom
fix/1.x-create-response-hardening
Nov 14, 2026
Merged

ddiazpinto merged 2 commits into
release/1.xfrom
fix/1.x-create-response-hardening

Conversation

@ddiazpinto

Copy link
Copy Markdown
Owner

Summary

  • create_response() verifies the signature before it reads any field. Before the check it reads at most 128 KiB of Ds_MerchantParameters and 128 characters of Ds_Signature, and rejects JSON nested deeper than 32 levels. Backport of fix: verify the signature before validating a received payload #63 (2.2.1).
  • Before, an unsigned payload posted to the notification URL was decoded first: JSON nested 9000 levels deep ends 1.2.2 with a segmentation fault on Python 3.12 and 3.13 with a 1 MiB thread stack, and Ds_Signature was normalized whatever its length.
  • Signatures are compared in constant time (hmac.compare_digest) instead of !=.
  • Any malformed payload raises ValueError; a missing Ds_Order, or one longer than 16 characters, fails the signature check instead of raising AttributeError or a PyCryptodome error.
  • Version 1.2.3.

Tests: 37 passed on Python 3.9, 3.10, 3.12, 3.13 and 3.15; ruff 0.1.3 clean; uv build and twine check pass.

Merge with rebase so release/1.x stays linear.

create_response() decoded Ds_MerchantParameters and built the Response
before checking Ds_Signature, so an unsigned payload posted to the
notification URL could crash the process with deeply nested JSON on a
small thread stack, have a Ds_Signature of any length normalized, or
raise TypeError, AttributeError, RecursionError or
decimal.InvalidOperation.

Before the signature check it now reads at most 128 KiB of
Ds_MerchantParameters and 128 characters of Ds_Signature, and rejects
JSON nested deeper than 32 levels. Fields are read only after the
signature matches, signatures compare in constant time, and any
malformed payload raises ValueError.

Backport of #63.
Version bump and changelog entry.
@ddiazpinto
ddiazpinto merged commit e34af76 into release/1.x Nov 14, 2026
1 check passed
@ddiazpinto
ddiazpinto deleted the fix/1.x-create-response-hardening branch November 14, 2026 03:29
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.

1 participant