Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing ILoggable in all relevant native auth classes #2081

Merged
merged 11 commits into from
Apr 25, 2024

Conversation

SammyO
Copy link
Contributor

@SammyO SammyO commented Apr 19, 2024

The default implementation of toString() of Kotlin's data classes uses all fields to compose the String. This unintentionally includes fields that may not be safe for logging.

Solution outline, see MSAL common PR: AzureAD/microsoft-authentication-library-common-for-android#2384

@github-actions github-actions bot added the msal label Apr 19, 2024
@SammyO SammyO marked this pull request as ready for review April 19, 2024 10:42
@SammyO SammyO requested review from a team as code owners April 19, 2024 10:42
SammyO added a commit to AzureAD/microsoft-authentication-library-common-for-android that referenced this pull request Apr 25, 2024
The default implementation of `toString()` of Kotlin's data classes uses
all fields to compose the String. This unintentionally includes fields
that may not be safe for logging.

Summary of solution:
- Introduce a new `Logging` interface. Recommendation is that all native
auth classes implement this interface.
- `Logging` contains 2 methods:
- `fun toUnsanitizedString(): String` - This method produces a String
that may contain PII (PII = Personally identifiable information). The
value of `containsPii()` will indicate whether the value actually
contains PII.
- `fun containsPii(): Boolean` - This method indicates whether the
implementing class contains data fields that are considered PII
(Personally identifiable information). If this method returns true, then
the value of `toSafeString(true)` will return a String that contains
PII.
- Extend `Logger` with a new methods `*withObject()` & parameter, e.g.:
`public static void infoWithObject(final String tag, final String
message, final Logging object)`. This logs safe object contents, based
on the value of Logger's `allowPii` and the object's `containsPii()`
value.
- If Logger's `allowPii` is false, then `object.toString()` is logged,
with `containsPii` set to `false`.
- If Logger's `allowPii` is true, then `object.toUnsanitised()` is
logged, with `containsPii` set to the object's `containsPii()`.
- Every class should implement `toString()` as well, in case an object
is accidentally turned into a String without using `toSafeString()`.
E.g. "SDK will return result $result" (which is short-hand for
`result.toString()`).
- `LoggerTest` has been updated with 4 additional test cases.

Note 1: it would have been more efficient to have `Logging` define
`override fun toString()`, meaning every class would be required to
override `toString()`. However, this is not possible in Kotlin (see
[link](https://stackoverflow.com/questions/53771394/override-and-implement-fn-from-class-in-interface)).

Note 2: the issue that this PR addresses applies to `data` classes.
However, this PR also includes some updates to regular classes, and
thereby partially addressing
https://identitydivision.visualstudio.com/Engineering/_workitems/edit/2811937

Accompanying MSAL PR:
AzureAD/microsoft-authentication-library-for-android#2081
@SammyO SammyO merged commit d70ec8c into dev Apr 25, 2024
8 checks passed
iamgusain pushed a commit that referenced this pull request Apr 25, 2024
The default implementation of `toString()` of Kotlin's data classes uses
all fields to compose the String. This unintentionally includes fields
that may not be safe for logging.

Solution outline, see MSAL common PR:
AzureAD/microsoft-authentication-library-common-for-android#2384
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants