Repository navigation
fix(1.x): verify the signature before reading the response (1.2.3) - #65
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
create_response()verifies the signature before it reads any field. Before the check it reads at most 128 KiB ofDs_MerchantParametersand 128 characters ofDs_Signature, and rejects JSON nested deeper than 32 levels. Backport of fix: verify the signature before validating a received payload #63 (2.2.1).Ds_Signaturewas normalized whatever its length.hmac.compare_digest) instead of!=.ValueError; a missingDs_Order, or one longer than 16 characters, fails the signature check instead of raisingAttributeErroror a PyCryptodome error.Tests: 37 passed on Python 3.9, 3.10, 3.12, 3.13 and 3.15; ruff 0.1.3 clean;
uv buildandtwine checkpass.Merge with rebase so
release/1.xstays linear.