Skip to content

fix(pii-safe): detect PII in nested type arguments - #11571

Merged
wmontwe merged 2 commits into
thunderbird:mainfrom
taljeon:codex/fix-pii-type-arguments
Sep 21, 2026
Merged

wmontwe merged 2 commits into
thunderbird:mainfrom
taljeon:codex/fix-pii-type-arguments

Conversation

@taljeon

@taljeon taljeon commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Contribution Summary

Linked Issue/Ticket: Fixes #11570
RFC / Technical Design (if applicable): N/A — focused compiler-plugin bug fix

Description

  • Recursively inspect resolved generic type arguments in HasPiiPropagationChecker, so an unannotated data class cannot hide a PII-bearing type inside nested containers.
  • Keep HasPiiRequiresAnnotatedPropertyChecker strict: a @HasPii data class is valid only when a property is directly @HasPii or explicitly uses @Mask/@Hide; a nested PII type alone is insufficient because the outer generic's toString() may leak it.
  • Add regressions for both boundaries: nested Map<String, List<MessageAddress>> propagation and an unmasked LeakyEnvelope<MessageAddress> property.

Before the initial implementation, the two nested-type regressions ran with the six existing focused tests and both failed. A review regression then demonstrated that the shared recursive predicate allowed an unmasked generic property to compile (1 of 4 annotation-required tests failed before the correction). After separating the policies, all eight focused tests pass.

Screen Shots

N/A — no UI changes.

AI Disclosure

Select one of the following (mandatory)

  • This contribution does not include any changes created or assisted by AI.
  • This contribution includes changes assisted by AI.
  • This contribution includes changes created by AI.

OpenAI Codex generated the implementation, tests, and pull request text. No manual human code review was performed before submission; the exact automated checks run are listed below.

Verification

Passed:

  • ./gradlew :library:pii-safe:compiler-plugin:test --tests 'net.thunderbird.piisafe.compiler.fir.checkers.HasPiiPropagationCheckerTest' --tests 'net.thunderbird.piisafe.compiler.fir.checkers.HasPiiRequiresAnnotatedPropertyCheckerTest' — 8 tests
  • ./gradlew :library:pii-safe:compiler-plugin:check — full module tests (41), Detekt, and Spotless
  • ./gradlew detekt spotlessCheck — repository-wide
  • git diff --check
  • isolated changed-file and PR-body leak checks

Not run locally:

  • ./gradlew test lint detekt spotlessCheck could not reach test or lint because this host has no Android SDK (ANDROID_HOME / sdk.dir). Repository-wide detekt and spotlessCheck were rerun separately and passed.
  • connectedAndroidTest was not run because no Android SDK/device is available; the changed module is a JVM compiler plugin and its focused/full module tests passed.

Contribution Checklist

  • I have read and affirm that my contribution adheres to Mozilla’s Community Participation Guidelines
  • This contribution is in Kotlin where possible
  • This contribution does not use merge commits
  • This contribution adheres to the existing codestyle (run gradlew spotlessCheck to check and gradlew spotlessApply to format your source code; will be checked by CI).
  • This contribution does not break existing unit tests (run gradlew testDebugUnitTest; will be checked by CI). The relevant JVM module suite passes; the repository-wide Android task is blocked locally by the missing SDK as documented above.
  • This contribution includes tests for any new functionality, and maintains tests for any updated functionality.
  • This contribution adheres to our Engineering process (RFC/Technical Design/ADR)
  • This PR has a descriptive title and body that accurately outlines all changes made, and contains a reference to any issues that it fixes (e.g. Closes #XXX or Fixes #XXX).

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ Validation Passed: All report and feature-flag labels are correctly set.

@taljeon

taljeon commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Could a maintainer apply report: exclude? This is an internal compiler-plugin correctness fix rather than a user-facing change. I attempted to set the required label, but contributor permissions do not allow it.

@wmontwe wmontwe added the report: exclude Exclude changes from user-facing reports (internal, minor, or not relevant to users). label Sep 16, 2026
@taljeon
taljeon marked this pull request as ready for review September 16, 2026 14:13
@taljeon
taljeon requested a review from a team as a code owner September 16, 2026 14:13
@taljeon
taljeon requested a review from wmontwe September 16, 2026 14:13

@wmontwe wmontwe left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Treating a nested @HasPii type argument as sufficient allows an unmasked generic property to bypass the existing safety check.

The generated toString() delegates to the outer generic type’s toString(), which is not guaranteed to preserve masking:

  @PiiSafe.HasPii                                                                                                                                                                                                                                                                                                                                                                   
  data class MessageAddress(@get:PiiSafe.Mask val value: String)                                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                                                                                    
  class LeakyEnvelope<T>(val value: T) {                                                                                                                                                                                                                                                                                                                                            
      override fun toString() = (value as MessageAddress).value                                                                                                                                                                                                                                                                                                                     
  }                                                                                                                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                    
  @PiiSafe.HasPii                                                                                                                                                                                                                                                                                                                                                                   
  data class MessageEnvelope(val secret: LeakyEnvelope<MessageAddress>)                                                                                                                                                                                                                                                                                                             

Before this change, MessageEnvelope fails compilation because secret needs @Mask or @Hide. With this change, it compiles and produces:

  MessageEnvelope(secret = private)                                                                                                                                                                                                                                                                                                                                                 

Could we keep recursive type-argument detection for HasPiiPropagationChecker, but only allow a directly @HasPii property OR an explicitly @Mask/@Hide property to satisfy HasPiiRequiresAnnotatedPropertyChecker?

@taljeon

taljeon commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — you're right. Recursive type-argument detection now remains only in HasPiiPropagationChecker.

HasPiiRequiresAnnotatedPropertyChecker now resolves only the property's outer return-type symbol, so it accepts a directly @HasPii property or an explicit @Mask/@Hide, but not an unmasked generic that merely contains a PII-bearing type.

I added the LeakyEnvelope<MessageAddress> case from the review as the regression. It compiled before the correction (1 of the 4 annotation-required tests failed against the expected diagnostic) and now fails compilation with HAS_PII_CLASS_WITHOUT_ANNOTATED_PROPERTY. The propagation check for nested Map<String, List<MessageAddress>> still passes.

Verification on the refreshed branch:

  • both checker suites: 8/8 tests pass;
  • :library:pii-safe:compiler-plugin:check: full module tests, Detekt, and Spotless pass;
  • repository-wide detekt spotlessCheck: pass.

@wmontwe wmontwe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix!

@wmontwe
wmontwe merged commit 8860132 into thunderbird:main Sep 21, 2026
17 checks passed
@thunderbird-botmobile

Copy link
Copy Markdown
Contributor

Thanks for your contribution! Your pull request has been merged and will be part of Thunderbird 25. We appreciate the time and effort you put into improving Thunderbird. If you haven’t already, you’re welcome to join our Matrix chat for contributors. It’s where we discuss development and help each other out. https://matrix.to/#/#tb-android-dev:mozilla.org
Hope to see you there! 🚀📱🐦

@thunderbird-botmobile thunderbird-botmobile Bot added this to the Thunderbird 25 milestone Sep 21, 2026

This branch was previously deployed

2 inactive (1 outdated) deployments
botmobile — b443e774 Deployed Sep 21, 2026 by wmontwe via pr-merged #522
review — 4b8de933 Deployed Sep 16, 2026 by taljeon via label-tb-team #513
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

report: exclude Exclude changes from user-facing reports (internal, minor, or not relevant to users).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Pii-Safe Compiler Plugin — FIR checker not considering Type Arguments annotated with @PiiSafe.HasPii

2 participants