Repository navigation
fix(java): Stop deobfuscating quoted values that are not classes. - #127244
Conversation
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
|
@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 |
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.
|
@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. On the broader question, happy to go with whatever @romtsn prefers, including adjusting the keyword list. |
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. |
|
@ranmori thanks for your contribution! the change should be rolled out in SaaS in the next few hours. |
|
@romtsn thank you!!! |
…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]>
ProGuard deobfuscation could rewrite ordinary quoted words in an exception message. With a mapping that obfuscates some class to
en, the messagehad its
'en'replaced with that unrelated class name. R8 also hands out names likean,or,ok,yesandno, so this is not a rare collision.Fixes #123739
The issue points at
deobfuscate_exception_valueinprocessing.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_REinsrc/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 oforinstance of. Dotted names and theX cannot be cast to Ypath are unchanged, soSerializer 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.pylocally; 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.