Uh oh!
There was an error while loading. Please reload this page.
Decode JWS payloads as UTF-8 instead of the JVM default charset - #266
Merged
alexanderjordanbaker merged 1 commit intoAug 27, 2026
Merged
Conversation
The payload of a JWS is always UTF-8, but parseJWTPayload converted the decoded bytes with new String(byte[]), which uses the JVM default charset. On the Java versions this library supports that charset is platform dependent, since JEP 400 only made UTF-8 the default in Java 18. On a JVM running with, for example, windows-1252 every non-ASCII character in a signed transaction, renewal info, notification or AppTransaction was silently corrupted: the signature still verified, so no error was raised and the caller received mojibake. Free-text fields such as the Advanced Commerce descriptors and the item displayName and description make this reachable for any non-English app. Also set the source encoding of the compile and javadoc tasks to UTF-8. Without it javac reads the sources with the platform charset, which corrupts the non-ASCII characters present in the javadoc of 25 files and prevents the new regression test from expressing its expected values.
alexanderjordanbaker
approved these changes
Aug 27, 2026
alexanderjordanbaker
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, thank you! Will be filing equivalent PRs on the other languages shortly
Uh oh!
There was an error while loading. Please reload this page.
alexanderjordanbaker added a commit
to apple/app-store-server-library-node
that referenced
this pull request
Aug 28, 2026
alexanderjordanbaker added a commit
to apple/app-store-server-library-python
that referenced
this pull request
Aug 28, 2026
alexanderjordanbaker added a commit
to apple/app-store-server-library-swift
that referenced
this pull request
Aug 28, 2026
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 freeto 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.
The problem
SignedDataVerifier.parseJWTPayload converts the base64url-decoded payload bytes into a String without specifying a charset:
String payload = new String(Base64.getUrlDecoder().decode(jwt.getPayload()));
new String(byte[]) uses the JVM default charset. A JWT Claims Set is always a UTF-8 encoded JSON object (RFC 7519 §3, RFC 8259 §8.1), so the two only agree when the JVM happens to run with UTF-8 as its default.
That is not guaranteed on the Java versions this library supports. JEP 400 made UTF-8 the default only in Java 18; on Java 11 through 17 the default charset comes from the platform locale, so a server running on Windows or with a non-UTF-8 LANG gets windows-1252, ISO-8859-1, Shift_JIS, and so on.
When that happens, every non-ASCII character in a decoded payload is corrupted silently. The signature is verified against the raw JWS, so verification still succeeds and no exception is raised — the caller simply receives mojibake. This affects every entry point that goes through decodeSignedObject: verifyAndDecodeTransaction, verifyAndDecodeRenewalInfo, verifyAndDecodeNotification, verifyAndDecodeAppTransaction and verifyAndDecodeRealtimeRequest.
It is easy to reach in practice. The Advanced Commerce descriptors and items carry merchant-supplied free text (displayName, description), so any app that is not English-only can hit it.
Reproduction
On JDK 17 with windows-1252 as the default charset, decoding a signed transaction whose advancedCommerceInfo.descriptors.description is Abonnement Café — 5,99 € par mois returns:
Abonnement Café — 5,99 € par mois
The existing test suite cannot catch this: all of its payload fixtures are ASCII-only, and CI sets JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8, which hides the difference.
The fix
new String(bytes, StandardCharsets.UTF_8) — one argument.
Source encoding
The build does not set options.encoding, so javac reads the sources with the platform charset too. 25 files under src/main contain non-ASCII characters (typographic apostrophes in the javadoc), which means those are corrupted in locally built javadoc on a non-UTF-8 machine. It also makes a regression test for this bug impossible to write in the natural way: the expected string literal would be corrupted by the compiler in exactly the same way as the actual value, and the assertion would pass.
This PR sets options.encoding = 'UTF-8' on the JavaCompile tasks and on javadoc. Note that ci-prb.yml currently compensates for the missing setting with JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8, while ci-release-javadocs.yml does not set it at all.
The test
SignedDataVerifierTest.testNonAsciiDataDecodingIsIndependentOfTheDefaultCharset decodes a new fixture containing French and Japanese text. Its expected values are written as \uXXXX escape sequences, so the test source is pure ASCII and the assertion does not depend on the encoding used to compile it.
Verification
On JDK 17, default charset windows-1252:
expected: <Abonnement Café — 5,99 € par mois> but was: <Abonnement Café — 5,99 € par mois>
Not included
Two related items I left out to keep the diff focused, happy to add them if you would prefer them here:
I also did not touch CHANGELOG.md, since it appears to be updated by maintainers in the release commits.