Skip to content

fix(java): Stop deobfuscating quoted values that are not classes. - #127244

Merged
romtsn merged 7 commits into
getsentry:masterfrom
ranmori:fix/proguard-quoted-value-deobfuscation
Oct 16, 2026
Merged

romtsn merged 7 commits into
getsentry:masterfrom
ranmori:fix/proguard-quoted-value-deobfuscation

Conversation

@ranmori

@ranmori ranmori commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

ProGuard deobfuscation could rewrite ordinary quoted words in an exception message. With a mapping that obfuscates some class to en, the message

requested 'en-IE', got 'en'

had its 'en' replaced with that unrelated class name. R8 also hands out names like an, or, ok, yes and no, so this is not a rare collision.

Fixes #123739

The issue points at deobfuscate_exception_value in processing.py, but that only replaces the top frame's <module>.<function>, which does not occur in this message. The replacement comes from _JAVA_CLASS_IN_TEXT_RE in src/sentry/lang/java/exceptions.py, which treated any quoted single identifier as a candidate class. This matches the diagnosis in getsentry/sentry-java#6056.

A quoted single identifier is now a candidate only when the message introduces it as a class, i.e. it directly follows class, subclass, superclass, interface, enum, type, serial name, scope of or instance of. Dotted names and the X cannot be cast to Y path are unchanged, so Serializer for subclass 'o' is not found in the polymorphic scope of "j4" still deobfuscates.

Trade-off: a message that quotes a real obfuscated class without one of those keywords (e.g. Got 'o') is no longer deobfuscated; one existing test relied on that and was reworded. The alternative is leaving the heuristic open, which keeps the false positives. The keyword list comes from the kotlinx.serialization messages that motivated #99927 and is the part most worth a reviewer's opinion.

I ran only tests/sentry/lang/java/test_exceptions.py locally; lint, mypy and the Symbolicator integration tests are left to CI.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Exception values were scanned for any quoted single identifier and each
one was offered to Symbolicator as a possible obfuscated class name. R8
hands out short names such as `en`, `no` or `ok`, so a message like
"requested 'en-IE', got 'en'" had its locale code replaced with an
unrelated class name.

Only treat a quoted single identifier as a class when the message
introduces it as one (class, subclass, type, scope of, serial name, ...).
Dotted names are matched as before.

Fixes getsentry#123739
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 13, 2026
@ranmori
ranmori marked this pull request as ready for review October 13, 2026 13:45
@ranmori
ranmori requested a review from a team as a code owner October 13, 2026 13:45
@ranmori
ranmori marked this pull request as draft October 13, 2026 13:45
@loewenheim

Copy link
Copy Markdown
Contributor

@romtsn I'd appreciate your opinion on this since you originally introduced this feature in #99927. Does it make sense to tighten the candidate regex and potentially lose some deobfuscation?

One problem I can see with this is that if the message matches the new tightened regex, but also contains an "accidental" class name, this will still be erroneously deobfuscated. For example, if the message is class 'en': requested 'en-IE', got 'en', all occurrences of "en" would be deobfuscated. But this may not be a real concern/worth the risk.

ranmori and others added 2 commits October 13, 2026 22:00
Deobfuscated names were substituted by searching the value for the
candidate's text, so a word introduced as a class once was replaced
everywhere, e.g. both occurrences in "class 'en': ... got 'en'".

Substitute each candidate at the position where it was matched instead.
Matches cannot overlap, so the longest-token-first ordering is no longer
needed.
@ranmori ranmori changed the title Fix/proguard quoted value deobfuscation fix(java): Stop deobfuscating quoted values that are not classes. Oct 13, 2026
@ranmori

ranmori commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@loewenheim Good catch. The replacement step searched for the token text, so a word that was introduced as a class once got replaced everywhere in the value.

I pushed a follow-up that replaces each candidate at the position where it was matched instead. class 'en': requested 'en-IE', got 'en' now becomes class '<mapped>': requested 'en-IE', got 'en', and I added that case as a test. It also removes the longest-token-first ordering, since matches no longer overlap.

On the broader question, happy to go with whatever @romtsn prefers, including adjusting the keyword list.

@romtsn

romtsn commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

@romtsn I'd appreciate your opinion on this since you originally introduced this feature in #99927. Does it make sense to tighten the candidate regex and potentially lose some deobfuscation?

One problem I can see with this is that if the message matches the new tightened regex, but also contains an "accidental" class name, this will still be erroneously deobfuscated. For example, if the message is class 'en': requested 'en-IE', got 'en', all occurrences of "en" would be deobfuscated. But this may not be a real concern/worth the risk.

thanks for the ping! Yeah, I think there's no really a good way to solve this without tradeoffs so I'm good with this change. We can then work off of the new issues and solve them case-by-case, if they ever arise.

@romtsn
romtsn marked this pull request as ready for review October 16, 2026 08:13
@romtsn
romtsn enabled auto-merge (squash) October 16, 2026 08:41
@romtsn romtsn added the Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests label Oct 16, 2026
@romtsn
romtsn merged commit 408a384 into getsentry:master Oct 16, 2026
113 of 115 checks passed
@romtsn

romtsn commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

@ranmori thanks for your contribution! the change should be rolled out in SaaS in the next few hours.

@ranmori

ranmori commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

@romtsn thank you!!!

RudraPatel2003 pushed a commit that referenced this pull request Oct 19, 2026
…27244)

ProGuard deobfuscation could rewrite ordinary quoted words in an
exception message. With a mapping that obfuscates some class to `en`,
the message

    requested 'en-IE', got 'en'

had its `'en'` replaced with that unrelated class name. R8 also hands
out names like `an`, `or`, `ok`, `yes` and `no`, so this is not a rare
collision.

Fixes #123739

The issue points at `deobfuscate_exception_value` in `processing.py`,
but that only replaces the top frame's `<module>.<function>`, which does
not occur in this message. The replacement comes from
`_JAVA_CLASS_IN_TEXT_RE` in `src/sentry/lang/java/exceptions.py`, which
treated any quoted single identifier as a candidate class. This matches
the diagnosis in getsentry/sentry-java#6056.

A quoted single identifier is now a candidate only when the message
introduces it as a class, i.e. it directly follows `class`, `subclass`,
`superclass`, `interface`, `enum`, `type`, `serial name`, `scope of` or
`instance of`. Dotted names and the `X cannot be cast to Y` path are
unchanged, so `Serializer for subclass 'o' is not found in the
polymorphic scope of "j4"` still deobfuscates.

Trade-off: a message that quotes a real obfuscated class without one of
those keywords (e.g. `Got 'o'`) is no longer deobfuscated; one existing
test relied on that and was reworded. The alternative is leaving the
heuristic open, which keeps the false positives. The keyword list comes
from the kotlinx.serialization messages that motivated #99927 and is the
part most worth a reviewer's opinion.

I ran only `tests/sentry/lang/java/test_exceptions.py` locally; lint,
mypy and the Symbolicator integration tests are left to CI.

### Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated
in the State of Delaware in 2015 as Functional Software, Inc. and is
gonna need some rights from me in order to utilize my contributions in
this here PR. So here's the deal: I retain all rights, title and
interest in and to my contributions, and by keeping this boilerplate
intact I confirm that Sentry can use, modify, copy, and redistribute my
contributions, under Sentry's choice of terms.

---------

Co-authored-by: Roman Zavarnitsyn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ProGuard deobfuscation can replace unrelated substrings in exception messages

3 participants