Skip to content

Commit 00d7b05

Browse files
authored
[v5] Strict matching default for MSAL Interceptor (#8355)
This PR makes strictMatching the default for the MSAL Angular interceptor.
1 parent b13f12b commit 00d7b05

10 files changed

+750
-63
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Make strictMatching default [#8355](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8355)",
4+
"packageName": "@azure/msal-angular",
5+
"email": "joarroyo@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Remove matchPattern from StringUtils [#8355](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8355)",
4+
"packageName": "@azure/msal-common",
5+
"email": "joarroyo@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

lib/msal-angular/docs/msal-interceptor.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,56 @@ Other things to note regarding the `protectedResourceMap`:
147147
* **Wildcards**: `protectedResourceMap` supports using `*` for wildcards. When using wildcards, if multiple matching entries are found in the `protectedResourceMap`, the first match found will be used (based on the order of the `protectedResourceMap`).
148148
* **Relative paths**: If there are relative resource paths in your application, you may need to provide the relative path in the `protectedResourceMap`. This also applies to issues that may arise with ngx-translate. Be aware that the relative path in your `protectedResourceMap` may or may not need a leading slash depending on your app, and may need to try both.
149149

150+
### Strict Matching (`strictMatching`)
151+
152+
In msal-angular v5, URL component pattern matching for `protectedResourceMap` entries uses strict matching semantics by default. The `strictMatching` field on `MsalInterceptorConfiguration` controls this behaviour.
153+
154+
#### What strict matching changes
155+
156+
| Behaviour | Legacy (`strictMatching: false`) | Strict (default in v5) |
157+
|-----------|----------------------------------|------------------------|
158+
| Metacharacter escaping | `.` and other regex metacharacters are **not** escaped; they act as regex operators | All metacharacters (including `.`) are treated as **literals** |
159+
| Anchoring | Pattern may match anywhere within the string | Pattern must match the **full string** (`^…$`) |
160+
| Host wildcard (`*`) | `*` matches any character sequence, including `.` | `*` matches any character sequence that does **not** include `.` (wildcards stay within a single DNS label) |
161+
| Path/search/hash wildcard (`*`) | `*` matches any character sequence | `*` matches any character sequence (unchanged) |
162+
| `?` character | Passed through to the underlying regex | Treated as a **literal** `?` (URL query-string separator, not a wildcard) |
163+
164+
With strict matching (the v5 default):
165+
- A pattern like `*.contoso.com` matches `app.contoso.com` but **not** `a.b.contoso.com` (wildcard cannot span dot separators).
166+
- A pattern like `https://graph.microsoft.com/v1.0/me` matches only that exact URL.
167+
168+
#### Default behaviour in v5 (no configuration needed)
169+
170+
Strict matching is enabled by default. No additional configuration is required:
171+
172+
```javascript
173+
{
174+
interactionType: InteractionType.Redirect,
175+
protectedResourceMap: new Map([
176+
["https://*.contoso.com/api", ["contoso.scope"]],
177+
["https://graph.microsoft.com/v1.0/me", ["user.read"]]
178+
])
179+
// strictMatching defaults to true in v5
180+
}
181+
```
182+
183+
#### Opting out to legacy matching (`strictMatching: false`)
184+
185+
If your patterns rely on the looser matching from v4, you can set `strictMatching: false` to retain the legacy behaviour temporarily:
186+
187+
> **Note:** Legacy matching (`strictMatching: false`) is provided for backwards compatibility and may be removed in a future major version. We recommend updating your `protectedResourceMap` patterns to work with strict matching.
188+
189+
```javascript
190+
{
191+
interactionType: InteractionType.Redirect,
192+
protectedResourceMap: new Map([
193+
["https://*.contoso.com/api", ["contoso.scope"]],
194+
["https://graph.microsoft.com/v1.0/me", ["user.read"]]
195+
]),
196+
strictMatching: false // Use legacy matching for backwards compatibility
197+
}
198+
```
199+
150200
### Optional authRequest
151201

152202
For more information on the optional `authRequest` that can be set in the `MsalInterceptorConfiguration`, please see our [multi-tenant doc here](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-angular/docs/multi-tenant.md#dynamic-auth-request).

lib/msal-angular/docs/v4-v5-upgrade-guide.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ MSAL Angular v5 requires a minimum version of Angular 19 and is dropping support
44

55
Please see the [MSAL Browser v4-v5 migration guide](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/v4-migration.md) for browser support and other key changes.
66

7-
## Changes in `@azure/msal-angular@5`
7+
## Breaking changes in `@azure/msal-angular@5`
8+
9+
### Strict matching for `protectedResourceMap`
10+
11+
In msal-angular v5, URL pattern matching for protectedResourceMap entries uses strict matching semantics by default. Strict matching treats pattern metacharacters as literals, anchors matches to the full URL component, and applies host wildcard rules that do not span dot separators. If your v4 configuration relied on looser matching behavior, update your protectedResourceMap patterns to align with strict matching, or set strictMatching to false to retain legacy behavior temporarily. See [MSAL Interceptor docs](./msal-interceptor.md#strict-matching-strictmatching) for more details.
12+
13+
## Other changes in `@azure/msal-angular@5`
814

915
### `inject(TOKEN)` syntax
1016

@@ -33,4 +39,4 @@ Note: Passing a hash string directly to `handleRedirectObservable(hash)` is now
3339

3440
### `logout()`
3541

36-
`logout()` has been removed. Please use `logoutRedirect()` or `logoutPopup()` instead.
42+
`logout()` has been removed. Please use `logoutRedirect()` or `logoutPopup()` instead.

lib/msal-angular/src/msal.interceptor.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ export type MsalInterceptorConfiguration = {
3131
req: HttpRequest<unknown>,
3232
originalAuthRequest: MsalInterceptorAuthRequest
3333
) => MsalInterceptorAuthRequest);
34+
/**
35+
* When `true` (the default in v5), enables stricter, more correct URL component pattern matching for
36+
* `protectedResourceMap` entries. Strict matching uses anchored regex patterns and
37+
* treats metacharacters (including `.`) as literals, so patterns match only their
38+
* intended strings. Wildcards still apply, but host-component wildcards
39+
* are constrained to a single DNS label.
40+
*
41+
* Set to `false` to use the legacy matching behaviour from v4 for
42+
* backwards compatibility.
43+
*
44+
* @default true
45+
*/
46+
strictMatching?: boolean;
3447
};
3548

3649
export type ProtectedResourceScopes = {

0 commit comments

Comments
 (0)