Skip to content

Check ASN.1 element types when extracting a transaction id from an app receipt - #221

Open
0z5a wants to merge 1 commit into
apple:mainfrom
0z5a:fix/receipt-asn1-type-checks
Open

0z5a wants to merge 1 commit into
apple:mainfrom
0z5a:fix/receipt-asn1-type-checks

Conversation

@0z5a

@0z5a 0z5a commented Nov 15, 2026

Copy link
Copy Markdown

ReceiptUtility.extract_transaction_id_from_app_receipt decoded the receipt payload, the in-app purchase receipt and the transaction identifier without looking at their ASN.1 types. A malformed receipt could therefore return an int (INTEGER transaction id), bytes (OCTET STRING) or a non-UTF8String str, and a non-SET payload or in-app purchase receipt was reported as "no in-app purchases" (None) instead of a malformed receipt.

This change checks that the payload and the in-app purchase receipt are SETs and that the transaction identifier is a UTF8String, and raises ValueError otherwise. This matches the Java library (ASN1Set / ASN1UTF8String checks) and the Node library (31 / 0c tag checks). Valid receipts, including the Xcode receipts in the test resources, are unaffected.

Tests: added a positive test with a synthetic receipt whose transaction id is a UTF8String, a test that INTEGER, OCTET STRING and IA5String transaction ids raise ValueError, and tests that an in-app purchase receipt or a receipt payload that is not a SET raises ValueError. The three negative tests fail on main (ValueError not raised) and pass with this change; python -m unittest passes (405 tests).

This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.

…p receipt

extract_transaction_id_from_app_receipt discarded the ASN.1 tags of the
receipt payload, the in-app array and the transaction id, so a malformed
receipt could return an int or bytes transaction id, or None when the
in-app container was not a SET. Require a SET for the payload and the
in-app array and a UTF8String for the transaction id, as the Java and
Node libraries do, and raise ValueError otherwise.

This branch has not been deployed

No deployments
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