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

[Identity] Allow Pii logging through MSAL #17321

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/identity/identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Features Added

- All of the credentials now include `enableUnsafeLogging` on their constructor options. If set to true, Personal Identifiable Information (PII) will be displayed in trace logs.

### Breaking Changes

#### Breaking Changes from 2.0.0-beta.5
Expand Down
1 change: 1 addition & 0 deletions sdk/identity/identity/review/identity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ export { TokenCredential }
export interface TokenCredentialOptions extends CommonClientOptions {
allowMultiTenantAuthentication?: boolean;
authorityHost?: string;
enableUnsafeLogging?: boolean;
}

// @public
Expand Down
6 changes: 6 additions & 0 deletions sdk/identity/identity/src/client/identityClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,10 @@ export interface TokenCredentialOptions extends CommonClientOptions {
* If set to true, allows authentication flows to change the tenantId of the request if a different tenantId is received from a challenge or through a direct getToken call.
*/
allowMultiTenantAuthentication?: boolean;

/**
* If set to true, personal data may be displayed in the trace logs depending on the authentication method.
* By default, this is disabled.
*/
enableUnsafeLogging?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class MSALAuthCode extends MsalBrowser {
};
this.msalConfig.system = {
loggerOptions: {
loggerCallback: defaultLoggerCallback(this.logger, "Browser")
loggerCallback: defaultLoggerCallback(this.logger, options.enableUnsafeLogging)
}
};

Expand Down
1 change: 1 addition & 0 deletions sdk/identity/identity/src/msal/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { CredentialFlowGetTokenOptions } from "./credentials";
*/
export interface MsalFlowOptions {
logger: CredentialLogger;
enableUnsafeLogging?: boolean;
clientId?: string;
tenantId?: string;
authorityHost?: string;
Expand Down
3 changes: 2 additions & 1 deletion sdk/identity/identity/src/msal/nodeFlows/nodeCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ export abstract class MsalNode extends MsalBaseUtilities implements MsalFlow {
system: {
networkClient: this.identityClient,
loggerOptions: {
loggerCallback: defaultLoggerCallback(options.logger)
piiLoggingEnabled: options.enableUnsafeLogging,
loggerCallback: defaultLoggerCallback(options.logger, options.enableUnsafeLogging)
}
}
};
Expand Down
8 changes: 5 additions & 3 deletions sdk/identity/identity/src/msal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ export function getKnownAuthorities(tenantId: string, authorityHost: string): st
*/
export const defaultLoggerCallback: (
logger: CredentialLogger,
platform?: "Node" | "Browser"
enableUnsafeLogging?: boolean
) => msalCommon.ILoggerCallback = (
logger: CredentialLogger,
platform: "Node" | "Browser" = isNode ? "Node" : "Browser"
enableUnsafeLogging: boolean = false
) => (level, message, containsPii): void => {
if (containsPii) {
const platform = isNode ? "Node" : "Browser";

if (containsPii && !enableUnsafeLogging) {
return;
}
switch (level) {
Expand Down