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

Bypassing redirect URI validation for nil URI if developers set bypassRedirectUriValidation property #2175

Merged
merged 6 commits into from
Jun 7, 2024

Conversation

borgesmb
Copy link
Contributor

@borgesmb borgesmb commented May 23, 2024

Proposed changes

Bypassing redirect URI validation for nil URI if developers set bypassRedirectUriValidation property. This PR has a dependency on: AzureAD/microsoft-authentication-library-common-for-objc#1375.

Type of change

  • Feature work
  • Bug fix
  • Documentation
  • Engineering change
  • Test
  • Logging/Telemetry

Risk

  • High – Errors could cause MAJOR regression of many scenarios. (Example: new large features or high level infrastructure changes)
  • Medium – Errors could cause regression of 1 or more scenarios. (Example: somewhat complex bug fixes, small new features)
  • Small – No issues are expected. (Example: Very small bug fixes, string changes, or configuration settings changes)

Additional information

@borgesmb borgesmb requested a review from a team as a code owner May 23, 2024 12:38
Copy link
Contributor

@nilo-ms nilo-ms left a comment

Choose a reason for hiding this comment

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

We should avoid modifying the MSAL public classes

@@ -879,6 +879,7 @@ - (void)acquireTokenSilentWithParameters:(MSALSilentTokenParameters *)parameters
// Nested auth protocol
msidParams.nestedAuthBrokerClientId = self.internalConfig.nestedAuthBrokerClientId;
msidParams.nestedAuthBrokerRedirectUri = self.internalConfig.nestedAuthBrokerRedirectUri;
msidParams.skipSendRedirectUri = [NSStringFromClass([self class]) isEqualToString:@"MSAL.MSALNativeAuthPublicClientApplication"];
Copy link
Contributor

@nilo-ms nilo-ms May 23, 2024

Choose a reason for hiding this comment

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

We can't only check the class name to set this parameter, what if the native auth user sets the redirect URI? In that case we should send it.

Here's my suggestion for this issue: We should make the redirect URI optional in MSAL. Currently, the redirect URI is always validated, even with the "bypassRedirectUriValidation" flag set to true, and this causes the MSAL public client application to fail the initialisation. See this code in IdentityCore here. If we change this behaviour, we can skip the default value for the redirect URI, and only send it when it's specified. We can start by looking at the IdentityCore code I mentioned and assess the impact of making the redirect URI optional.

Copy link
Contributor Author

@borgesmb borgesmb May 23, 2024

Choose a reason for hiding this comment

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

Fair point, right now is not possible to pass nil as the redirect URI, so is impossible to know for certain that the developer wants or not to use it. I'll look into your suggestion, but I think that is not the only validation that we need to surpass. We need to understand why is not possible to have a nil redirect URI on MSAL Objective-C, if this is possible in Android. Do we have a design/conceptual reason for that @antrix1989 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing the mentioned code won't have the intended effect, since this method will return a nil instance of MSIDRedirectUri, which is what we want if developers don't pass a redirect URI. There are other points in MSAL and IdentityCore that are not taking in consideration the bypassRedirectUriValidation parameter. I think that the latest change in this PR addresses that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the IdentityCore PR as well.

@borgesmb borgesmb requested a review from antrix1989 May 23, 2024 17:34
…ic client config

Bypassing nil redirect URI if developer sets "bypassRedirectURIValidation"
Passing configuration to silent token request parameters
Copy link
Contributor Author

@borgesmb borgesmb left a comment

Choose a reason for hiding this comment

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

.

@borgesmb borgesmb changed the title Passing new parameter "skipSendRedirectUri" from public client applic… Bypassing redirect URI validation for nil URI if developers set bypassRedirectUriValidation property May 24, 2024
Copy link
Contributor

@antrix1989 antrix1989 left a comment

Choose a reason for hiding this comment

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

Please add unit tests.

…er passes a nil redirect URI

- Testing `bypassRedirectURIValidation` when copying MSALPublicClientApplicationConfig
@nilo-ms nilo-ms force-pushed the borgesmb/optional-redirect-uri branch from e480d9a to acf907c Compare June 7, 2024 09:20
This test was having this behaviour only because the redirectURI in info plist was not matching the default redirect uri (the behaviour was not related to the byPassRedirectURIValidation param)
@nilo-ms nilo-ms requested a review from a team as a code owner June 7, 2024 16:24
@nilo-ms nilo-ms merged commit 89fae42 into dev Jun 7, 2024
6 checks passed
@kaisong1990 kaisong1990 deleted the borgesmb/optional-redirect-uri branch June 7, 2024 18:04
antonioalwan added a commit that referenced this pull request Jun 18, 2024
* dev:
  share ownership of CHANGELOG file (#2194)
  Add platform sequence param. (#2192)
  Submodule update (#2189)
  Feature/multiple tokens 4 (#2159)
  Bypassing redirect URI validation for nil URI if developers set bypassRedirectUriValidation property (#2175)
  Update submodule
  Update submodule
  Add new error code when SSO ext config doesn't contain valid Error Handling config

# Conflicts:
#	MSAL/IdentityCore
#	MSAL/src/MSALErrorConverter.m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants