Skip to content

fix: verify the signature before validating a received payload - #63

Merged
ddiazpinto merged 1 commit into
masterfrom
fix/parse-response-hardening
Nov 14, 2026
Merged

ddiazpinto merged 1 commit into
masterfrom
fix/parse-response-hardening

Conversation

@ddiazpinto

Copy link
Copy Markdown
Owner

parse_response() decoded and validated Ds_MerchantParameters before
checking Ds_Signature, so an unsigned payload posted to the notification
URL could raise decimal.Overflow and other unexpected exceptions, nested
JSON could exhaust a small thread stack and crash the process, and an
oversized Ds_Signature was normalized whatever its length.

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 validated only after the
signature matches. Any malformed payload, and a send() answer that is
not JSON, raises redsys.exceptions.ValidationError, a ValueError; a
signature mismatch still raises ValueError.

parse_response() decoded and validated Ds_MerchantParameters before
checking Ds_Signature, so an unsigned payload posted to the notification
URL could raise decimal.Overflow and other unexpected exceptions, nested
JSON could exhaust a small thread stack and crash the process, and an
oversized Ds_Signature was normalized whatever its length.

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 validated only after the
signature matches. Any malformed payload, and a send() answer that is
not JSON, raises redsys.exceptions.ValidationError, a ValueError; a
signature mismatch still raises ValueError.
@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.12%. Comparing base (a056745) to head (f9a4f22).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #63      +/-   ##
==========================================
- Coverage   99.16%   99.12%   -0.05%     
==========================================
  Files          26       26              
  Lines        1315     1368      +53     
==========================================
+ Hits         1304     1356      +52     
- Misses         11       12       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ddiazpinto
ddiazpinto merged commit 3ea6c51 into master Nov 14, 2026
14 of 15 checks passed
@ddiazpinto
ddiazpinto deleted the fix/parse-response-hardening branch November 14, 2026 03:04
ddiazpinto added a commit that referenced this pull request Nov 14, 2026
* fix: verify the signature before reading the response

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.

* chore(release): 1.2.3

Version bump and changelog entry.
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