oidc-spa 8.2.10 → 8.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +194 -22
- package/core/createOidc.js +1 -1
- package/core/earlyInit.js +2 -2
- package/core/earlyInit.js.map +1 -1
- package/core/iframeMessageProtection.d.ts +5 -2
- package/core/iframeMessageProtection.js +44 -19
- package/core/iframeMessageProtection.js.map +1 -1
- package/esm/core/createOidc.js +1 -1
- package/esm/core/earlyInit.js +3 -3
- package/esm/core/earlyInit.js.map +1 -1
- package/esm/core/iframeMessageProtection.d.ts +5 -2
- package/esm/core/iframeMessageProtection.js +43 -17
- package/esm/core/iframeMessageProtection.js.map +1 -1
- package/esm/react-spa/createOidcSpaApi.js +1 -1
- package/esm/react-spa/createOidcSpaApi.js.map +1 -1
- package/esm/react-spa/types.d.ts +5 -5
- package/esm/tanstack-start/react/createOidcSpaApi.js +107 -88
- package/esm/tanstack-start/react/createOidcSpaApi.js.map +1 -1
- package/esm/tanstack-start/react/types.d.ts +43 -21
- package/esm/tanstack-start/react/withHandlingOidcPostLoginNavigation.js +13 -2
- package/esm/tanstack-start/react/withHandlingOidcPostLoginNavigation.js.map +1 -1
- package/package.json +1 -1
- package/react-spa/createOidcSpaApi.js +1 -1
- package/react-spa/createOidcSpaApi.js.map +1 -1
- package/react-spa/types.d.ts +5 -5
- package/src/core/earlyInit.ts +5 -7
- package/src/core/iframeMessageProtection.ts +55 -22
- package/src/react-spa/createOidcSpaApi.tsx +1 -1
- package/src/react-spa/types.tsx +5 -5
- package/src/tanstack-start/react/createOidcSpaApi.tsx +145 -153
- package/src/tanstack-start/react/types.tsx +40 -29
- package/src/tanstack-start/react/withHandlingOidcPostLoginNavigation.tsx +13 -2
package/README.md
CHANGED
|
@@ -24,37 +24,208 @@
|
|
|
24
24
|
<a href="https://docs.oidc-spa.dev">Documentation</a>
|
|
25
25
|
</p>
|
|
26
26
|
|
|
27
|
+
## At a glance
|
|
28
|
+
|
|
29
|
+
The Framework Agnostic Adapter:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { createOidc } from "oidc-spa/core";
|
|
33
|
+
import { z } from "zod";
|
|
34
|
+
|
|
35
|
+
const oidc = await createOidc({
|
|
36
|
+
issuerUri: "https://auth.my-domain.net/realms/myrealm",
|
|
37
|
+
//issuerUri: "https://login.microsoftonline.com/...",
|
|
38
|
+
//issuerUri: "https://xxx.us.auth0.com/..."
|
|
39
|
+
//issuerUri: "https://accounts.google.com/o/oauth2/v2/auth"
|
|
40
|
+
clientId: "myclient",
|
|
41
|
+
decodedIdTokenSchema: z.object({
|
|
42
|
+
name: z.string(),
|
|
43
|
+
picture: z.string().optional(),
|
|
44
|
+
email: z.string(),
|
|
45
|
+
realm_access: z.object({ roles: z.array(z.string()) })
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (!oidc.isUserLoggedIn) {
|
|
50
|
+
oidc.login();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const { name, realm_access } = oidc.getDecodedIdToken();
|
|
55
|
+
|
|
56
|
+
console.log(`Hello ${name}`);
|
|
57
|
+
|
|
58
|
+
const { accessToken } = await oidc.getTokens();
|
|
59
|
+
|
|
60
|
+
await fetch("https://my-domain.net/api/todos", {
|
|
61
|
+
headers: {
|
|
62
|
+
Authorization: `Bearer ${accessToken}`
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (realm_access.roles.includes("realm-admin")) {
|
|
67
|
+
// User is an admin
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Higher level adapters, example with React but we also feature similar Angular adapter:
|
|
72
|
+
|
|
73
|
+
<img width="1835" height="942" alt="Image" src="https://github.com/user-attachments/assets/a7a18bbc-998a-459c-8cfa-93b599a45524" />
|
|
74
|
+
|
|
75
|
+
Full Stack Auth solution with [TanStack Start]():
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
79
|
+
import { enforceLogin, oidcFnMiddleware } from "@/oidc";
|
|
80
|
+
import fs from "node:fs/promises";
|
|
81
|
+
|
|
82
|
+
const getTodos = createServerFn({ method: "GET" })
|
|
83
|
+
.middleware([oidcFnMiddleware({ assert: "user logged in" })])
|
|
84
|
+
.handler(async ({ context: { oidc } }) => {
|
|
85
|
+
const userId = oidc.accessTokenClaims.sub;
|
|
86
|
+
|
|
87
|
+
const json = await fs.readFile(`todos_${userId}.json`, "utf8");
|
|
88
|
+
|
|
89
|
+
return JSON.parse(json);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const Route = createFileRoute("/todos")({
|
|
93
|
+
beforeLoad: enforceLogin,
|
|
94
|
+
loader: () => getTodos(),
|
|
95
|
+
component: RouteComponent
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
function RouteComponent() {
|
|
99
|
+
const todos = Route.useLoaderData();
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<ul>
|
|
103
|
+
{todos.map(todo => (
|
|
104
|
+
<li key={todo.id}>
|
|
105
|
+
{todo.isDone && "✅"} {todo.text}
|
|
106
|
+
</li>
|
|
107
|
+
))}
|
|
108
|
+
</ul>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
27
113
|
## What this is
|
|
28
114
|
|
|
29
|
-
oidc-spa is
|
|
115
|
+
oidc-spa is a framework-agnostic OpenID Connect client for browser-centric web applications implementing the [Authorization Code Flow with PKCE](https://docs.oidc-spa.dev/resources/why-no-client-secret).
|
|
116
|
+
|
|
117
|
+
It work with any spec compliant OIDC provider like [Keycloak](https://www.keycloak.org/), [Auth0](https://auth0.com/) or [Microsoft EntraID](https://www.microsoft.com/fr-fr/security/business/identity-access/microsoft-entra-id) and replace provider-specific SDKs like [keycloak-js](https://www.npmjs.com/package/keycloak-js), [auth0-spa-js](https://www.npmjs.com/package/@auth0/auth0-spa-js), or [@azure/msal-browser](https://www.npmjs.com/package/@azure/msal-browser) with one unified API, freeing your app from vendor lock-in and making it deployable in any IT system.
|
|
118
|
+
Concretely this mean that it let you build an app and sell it to different companies ensuring they will be able to deploy it in their environment regardless of what auth platform they use internally.  
|
|
30
119
|
|
|
31
|
-
oidc-spa
|
|
120
|
+
oidc-spa provides strong guarantees regarding the protection of your tokens [**even in case of successful XSS or supply chain attacks**](https://docs.oidc-spa.dev/v/v8/resources/xss-and-supply-chain-attack-protection). No other implementation can currently claim that.  
|
|
32
121
|
|
|
33
|
-
|
|
122
|
+
It is uncompromising in terms of performance, security, DX, and UX. You get a state-of-the-art authentication and authorization system out of the box with zero glue code to write and no knobs to adjust.
|
|
34
123
|
|
|
35
|
-
|
|
124
|
+
Unlike server-centric solutions such as [Auth.js](https://authjs.dev/), oidc-spa makes the frontend the OIDC client in your IdP model's representation.
|
|
36
125
|
|
|
37
|
-
|
|
126
|
+
Your backend becomes a simple OAuth2 resource server that you frontend query with the access token attached as Authorization header. oidc-spa also provides the tools for token validation on the server side:
|
|
38
127
|
|
|
39
|
-
|
|
128
|
+
- As an unified solution for [TanStack Start](https://tanstack.com/router/latest) 
|
|
129
|
+
- Or, as [a separate adapter](integration-guides/tanstack-router-+-node-rest-api.md) for creating authed APIs with [tRCP](https://trpc.io/), [Express](https://expressjs.com/), [Hono](https://hono.dev/), [Nest.js](https://nestjs.com/), ect.
|
|
40
130
|
|
|
41
|
-
That means no database
|
|
131
|
+
That means **no database,** no session store, and **enterprise-grade UX** out of the box, while scaling naturally to edge runtimes.
|
|
42
132
|
|
|
43
|
-
oidc-spa exposes real OIDC primitives, ID tokens, access tokens, and claims
|
|
133
|
+
oidc-spa exposes real OIDC primitives, decoded ID tokens, access tokens, and claims, instead of hiding them behind a “user” object, helping you understand and control your security posture.
|
|
44
134
|
|
|
45
135
|
It’s infra-light, open-standard, transparent, and ready to work in minutes.
|
|
46
136
|
|
|
47
|
-
|
|
137
|
+
<details>
|
|
138
|
+
|
|
139
|
+
<summary>But in details? I want to understand the tradeoffs.</summary>
|
|
140
|
+
<br />
|
|
141
|
+
|
|
142
|
+
In the modern tech ecosystem, no one “rolls their own auth” anymore, not even OpenAI or Vercel.\
|
|
143
|
+
Authentication has become a **platform concern**. Whether you host your own identity provider like **Keycloak**, or use a service such as **Auth0** or **Microsoft Entra ID**, authentication today means **redirecting users to your auth provider**.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
**Why not** [**BetterAuth**](https://www.better-auth.com/) **or** [**Auth.js**](https://authjs.dev/)
|
|
148
|
+
|
|
149
|
+
These are great for what they are, but they’re “roll your own auth” solutions.\
|
|
150
|
+
With oidc-spa, you delegate authentication to a specialized identity provider such as Keycloak, Auth0, Okta, or Clerk.
|
|
151
|
+
|
|
152
|
+
With BetterAuth, your backend _is_ the authorization server, even if you can integrate third party identity providers id doesn't change that fact.\
|
|
153
|
+
That’s very battery-included, but also far heavier infrastructure-wise.\
|
|
154
|
+
Today, very few companies still roll their own auth, not even OpenAI or Vercel.
|
|
155
|
+
|
|
156
|
+
Another big difference: oidc-spa is **browser-centric**. The token exchange happens on the client,\
|
|
157
|
+
and the backend server is merely an OAuth2 resource server in the OIDC model.
|
|
158
|
+
|
|
159
|
+
If you use BetterAuth to provide login via Keycloak, your backend becomes the OIDC client application,\
|
|
160
|
+
which has some security benefits over browser token exchange, but at the cost of centralization and requiring backend infrastructure.
|
|
161
|
+
|
|
162
|
+
One clear advantage BetterAuth has over oidc-spa is more natural SSR support. In the oidc-spa model, the server doesn’t know the authentication state of the user at all time, which makes it difficult to integrate with traditional full-stack frameworks that rely on server-side rendering.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
**Server Side Rendering**
|
|
167
|
+
|
|
168
|
+
The only SSR-capable framework we currently support is [TanStack Start](https://tanstack.com/start/latest), because it provides the low-level primitives needed to render as much as possible on the server while deferring rendering of auth aware components to the client.
|
|
48
169
|
|
|
49
|
-
|
|
170
|
+
This approach achieves a similar UX and performance to server-centric frameworks, but it’s inherently less transparent than streaming fully authenticated components to the client.
|
|
50
171
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
172
|
+
Try the TansStack Start example deployment with JavaScript disabled to get a feel of what can and can't be SSR'd: [https://example-tanstack-start.oidc-spa.dev/](https://example-tanstack-start.oidc-spa.dev/)
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
**Security and XSS resilience**
|
|
177
|
+
|
|
178
|
+
Yes; client-side authentication raises valid security concerns.\
|
|
179
|
+
But this isn’t a fatal flaw; it’s an **engineering challenge**, and oidc-spa addresses it head-on.
|
|
180
|
+
|
|
181
|
+
It treats the browser as a **hostile environment**, going to great lengths to protect tokens even under **XSS or supply-chain attacks**.\
|
|
182
|
+
These mitigations [are documented here](resources/why-no-client-secret.md).
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
**Limitations regarding backend delegation**
|
|
187
|
+
|
|
188
|
+
The main limitation is with **long-running background operations**.\
|
|
189
|
+
If your backend must call third-party APIs **on behalf of the user** while they’re offline, you’ll need **service accounts** for those APIs or take charge of rotating tokens yourself which [can be tricky](https://authjs.dev/guides/refresh-token-rotation).\
|
|
190
|
+
Beyond that, everything else scalability, DX, performance, works in your favor.
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
If that all sounds good to you…\
|
|
195
|
+
**Let’s get started.**
|
|
196
|
+
|
|
197
|
+
</details>
|
|
198
|
+
|
|
199
|
+
## Integration
|
|
200
|
+
|
|
201
|
+
- Full Stack - all in one auth solution:
|
|
202
|
+
- [TanStack Start](https://docs.oidc-spa.dev/integration-guides/tanstack-start)
|
|
203
|
+
- Single Page Apps (SPAs):
|
|
204
|
+
- [Framework Agnostic](https://docs.oidc-spa.dev/integration-guides/usage)
|
|
205
|
+
- [React Router](https://docs.oidc-spa.dev/integration-guides/react-router)
|
|
206
|
+
- [Tanstack Router](https://docs.oidc-spa.dev/integration-guides/tanstack-router-start/react-router)
|
|
207
|
+
- [Angular](https://docs.oidc-spa.dev/integration-guides/angular)
|
|
208
|
+
- ...More to come...
|
|
209
|
+
- Backend: [Express, Hono, tRPC, Nest.js ...](https://docs.oidc-spa.dev/integration-guides/tanstack-router-+-node-rest-api)
|
|
55
210
|
|
|
56
211
|
## Comparison with Existing Libraries
|
|
57
212
|
|
|
213
|
+
With other OIDC clients, you'll get something that works in the happy path.
|
|
214
|
+
But then you will face issues like:
|
|
215
|
+
|
|
216
|
+
- The user cannot navigate back from the login page to your app.
|
|
217
|
+
- User get hit with "your session has expired please login again" after spending an hours filling your form.
|
|
218
|
+
- User logged out or logged in on one tabe but the state is not propagated to the other tabs.
|
|
219
|
+
- Random 401 from your API with "token expired"
|
|
220
|
+
- You can't run E2E test without having to actually connect to a real server.
|
|
221
|
+
|
|
222
|
+
Plus you'll realize that your configuration works with one provider in one devloppement configuration,
|
|
223
|
+
try to switch IdP and the all thing fall appart, you'll be met with criptic errors and have to spend
|
|
224
|
+
days tweeking knobs again.
|
|
225
|
+
|
|
226
|
+
With oidc-spa, there's no knobs to adjust, things just work out of the box.
|
|
227
|
+
And you get XSS and suply chain attack protection, unlike with any other client side solution.
|
|
228
|
+
|
|
58
229
|
### [oidc-client-ts](https://github.com/authts/oidc-client-ts)
|
|
59
230
|
|
|
60
231
|
It is a great low-level implementation of the OIDC primitives.
|
|
@@ -65,12 +236,13 @@ code that has no business living in application-level logic.
|
|
|
65
236
|
Example of what you get out of the box with oidc-spa:
|
|
66
237
|
|
|
67
238
|
- **Login/logout propagation** across tabs
|
|
68
|
-
- **
|
|
239
|
+
- **SSO that just works**, regardless of the deployment configuration.
|
|
69
240
|
- **Seamless browser back/forward cache (bfcache) management**
|
|
70
|
-
- **Auto logout
|
|
241
|
+
- **Auto logout**: avoid "your session has expired please login again" after the used just spend an hour filling your form.
|
|
71
242
|
- **Never getting an expired access token error**, even after waking from sleep
|
|
72
243
|
- **Graceful handling when the provider lacks refresh tokens or a logout endpoint** (e.g. Google OAuth)
|
|
73
244
|
- **Mock support**, run with a mock identity without contacting a server
|
|
245
|
+
- **Helpfull debug logs** important if you sell your solution, to streamline deployment.
|
|
74
246
|
|
|
75
247
|
oidc-spa just works. You provide the few parameters required to talk to your IdP, and that’s it.
|
|
76
248
|
|
|
@@ -115,27 +287,27 @@ oidc-spa exposes an Angular adapter: [oidc-spa/angular](https://docs.oidc-spa.de
|
|
|
115
287
|
This is a solid generic OIDC adapter.
|
|
116
288
|
However, `oidc-spa/angular` still has several advantages:
|
|
117
289
|
|
|
118
|
-
- [Better security guarantees](https://docs.oidc-spa.dev/resources/
|
|
119
|
-
-
|
|
290
|
+
- [Better security guarantees](https://docs.oidc-spa.dev/resources/xss-and-supply-chain-attack-protection) (angular-oauth2-oidc does not protect tokens from XSS or supply-chain attacks)
|
|
291
|
+
- DX more aligned with modern Angular.
|
|
120
292
|
- Auto logout overlay (“Are you still there?” countdown)
|
|
121
293
|
- Stronger type safety with propagated user profile types
|
|
122
294
|
- Ability to start rendering before session restoration settles
|
|
123
295
|
- Support for multiple resource servers
|
|
124
296
|
- Clearer and more actionable error messages for misconfiguration
|
|
125
297
|
|
|
126
|
-
### [BetterAuth](https://www.better-auth.com/) / [
|
|
298
|
+
### [BetterAuth](https://www.better-auth.com/) / [Auth.js](https://authjs.dev/)
|
|
127
299
|
|
|
128
|
-
These are great for what they are
|
|
300
|
+
These are great for what they are, but they’re “roll your own auth” solutions.
|
|
129
301
|
With oidc-spa, you delegate authentication to a specialized identity provider such as Keycloak, Auth0, Okta, or Clerk.
|
|
130
302
|
|
|
131
|
-
With BetterAuth, your backend _is_ the authorization server.
|
|
303
|
+
With BetterAuth, your backend _is_ the authorization server. (even if you can integrate third party provider).
|
|
132
304
|
That’s very battery-included, but also far heavier infrastructure-wise.
|
|
133
305
|
Today, very few companies still roll their own auth—including OpenAI and Vercel.
|
|
134
306
|
|
|
135
307
|
Another big difference: oidc-spa is **browser-centric**. The token exchange happens on the client,
|
|
136
308
|
and the backend server is merely an OAuth2 resource server in the OIDC model.
|
|
137
309
|
|
|
138
|
-
If you use BetterAuth to provide login via Keycloak, your backend becomes the OIDC client application
|
|
310
|
+
If you use BetterAuth to provide login via Keycloak, your backend becomes the OIDC client application,
|
|
139
311
|
which has some security benefits over browser token exchange, but at the cost of centralization and requiring backend infrastructure.
|
|
140
312
|
|
|
141
313
|
One clear advantage BetterAuth has over oidc-spa is SSR support.
|
package/core/createOidc.js
CHANGED
|
@@ -71,7 +71,7 @@ const instancesThatCantUseIframes_1 = require("./instancesThatCantUseIframes");
|
|
|
71
71
|
const desiredPostLoginRedirectUrl_1 = require("./desiredPostLoginRedirectUrl");
|
|
72
72
|
const homeAndRedirectUri_1 = require("./homeAndRedirectUri");
|
|
73
73
|
// NOTE: Replaced at build time
|
|
74
|
-
const VERSION = "8.2.
|
|
74
|
+
const VERSION = "8.2.12";
|
|
75
75
|
const globalContext = {
|
|
76
76
|
prOidcByConfigId: new Map(),
|
|
77
77
|
hasLogoutBeenCalled: (0, id_1.id)(false)
|
package/core/earlyInit.js
CHANGED
|
@@ -19,7 +19,6 @@ function oidcEarlyInit(params) {
|
|
|
19
19
|
if (!isBrowser_1.isBrowser) {
|
|
20
20
|
return { shouldLoadApp: true };
|
|
21
21
|
}
|
|
22
|
-
(0, iframeMessageProtection_1.captureApisForIframeProtection)();
|
|
23
22
|
const { freezeFetch, freezeXMLHttpRequest, freezeWebSocket = false, isPostLoginRedirectManual = false, BASE_URL } = params;
|
|
24
23
|
const { shouldLoadApp } = handleOidcCallback({ isPostLoginRedirectManual });
|
|
25
24
|
if (shouldLoadApp) {
|
|
@@ -55,10 +54,10 @@ function oidcEarlyInit(params) {
|
|
|
55
54
|
value: WebSocket_trusted
|
|
56
55
|
});
|
|
57
56
|
}
|
|
58
|
-
(0, iframeMessageProtection_1.preventSessionStorageSetItemOfPublicKeyByThirdParty)();
|
|
59
57
|
if (BASE_URL !== undefined) {
|
|
60
58
|
(0, BASE_URL_1.setBASE_URL)({ BASE_URL });
|
|
61
59
|
}
|
|
60
|
+
(0, iframeMessageProtection_1.iframeMessageProtection_captureAndLockBuiltins)();
|
|
62
61
|
}
|
|
63
62
|
(0, prShouldLoadApp_1.resolvePrShouldLoadApp)({ shouldLoadApp });
|
|
64
63
|
return { shouldLoadApp };
|
|
@@ -154,6 +153,7 @@ function handleOidcCallback(params) {
|
|
|
154
153
|
})();
|
|
155
154
|
if (isPostLoginRedirectManual) {
|
|
156
155
|
(0, requiredPostHydrationReplaceNavigationUrl_1.setOidcRequiredPostHydrationReplaceNavigationUrl)({ rootRelativeRedirectUrl });
|
|
156
|
+
history.replaceState({}, "", rootRelativeOriginalLocationHref);
|
|
157
157
|
}
|
|
158
158
|
else {
|
|
159
159
|
history.replaceState({}, "", rootRelativeRedirectUrl);
|
package/core/earlyInit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"earlyInit.js","sourceRoot":"","sources":["../src/core/earlyInit.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"earlyInit.js","sourceRoot":"","sources":["../src/core/earlyInit.ts"],"names":[],"mappings":";;AAcA,sCAiFC;AAID,0DAaC;AAID,kFAGC;AAvHD,2CAAqE;AACrE,kDAA4D;AAE5D,uEAGmC;AACnC,2GAA+G;AAC/G,yCAAyC;AACzC,uDAA2D;AAC3D,kDAA+C;AAE/C,IAAI,sBAAsB,GAAG,KAAK,CAAC;AAEnC,SAAgB,aAAa,CAAC,MAQ7B;IACG,IAAI,sBAAsB,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC5E,CAAC;IAED,sBAAsB,GAAG,IAAI,CAAC;IAE9B,IAAI,CAAC,qBAAS,EAAE,CAAC;QACb,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,EACF,WAAW,EACX,oBAAoB,EACpB,eAAe,GAAG,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AAK,EAAE,CAAC;QACpC,KAAK,UAAU,CAAC,CAAC,CAAC;YACd,oBAAoB,GAAG,YAAY,CAAC;YAEpC,MAAM,uBAAuB,GAAG,CAAC,GAAG,EAAE;gBAClC,IAAI,SAAS,CAAC,MAAM,KAAK,OAAO,IAAI,YAAY,CAAC,KAAK,KAAK,kBAAkB,EAAE,CAAC;oBAC5E,OAAO,SAAS,CAAC,2CAA2C,CAAC;gBACjE,CAAC;gBACD,OAAO,SAAS,CAAC,uBAAuB,CAAC;YAC7C,CAAC,CAAC,EAAE,CAAC;YAEL,IAAI,yBAAyB,EAAE,CAAC;gBAC5B,IAAA,4FAAgD,EAAC,EAAE,uBAAuB,EAAE,CAAC,CAAC;gBAC9E,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE,gCAAgC,CAAC,CAAC;YACnE,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE,uBAAuB,CAAC,CAAC;YAC1D,CAAC;YAED,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;QACnC,CAAC;QACD;YACI,IAAA,eAAM,EAAkC,KAAK,CAAC,CAAC;IACvD,CAAC;AACL,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type AuthResponse } from "./AuthResponse";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* To call while still in the safe window where no other code
|
|
4
|
+
* has been evaluated and only before we're about to actually start the App.
|
|
5
|
+
*/
|
|
6
|
+
export declare function iframeMessageProtection_captureAndLockBuiltins(): void;
|
|
4
7
|
declare function getIsEncryptedAuthResponse(params: {
|
|
5
8
|
message: unknown;
|
|
6
9
|
stateUrlParamValue: string;
|
|
@@ -1,38 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.preventSessionStorageSetItemOfPublicKeyByThirdParty = preventSessionStorageSetItemOfPublicKeyByThirdParty;
|
|
3
|
+
exports.iframeMessageProtection_captureAndLockBuiltins = iframeMessageProtection_captureAndLockBuiltins;
|
|
5
4
|
exports.initIframeMessageProtection = initIframeMessageProtection;
|
|
6
5
|
exports.postEncryptedAuthResponseToParent = postEncryptedAuthResponseToParent;
|
|
7
6
|
const assert_1 = require("../tools/tsafe/assert");
|
|
8
7
|
const asymmetricEncryption_1 = require("../tools/asymmetricEncryption");
|
|
9
8
|
let capturedApis = undefined;
|
|
10
|
-
|
|
9
|
+
const SESSION_STORAGE_PREFIX = "oidc-spa_iframe_authResponse_publicKey_";
|
|
10
|
+
const getProtectedTimer_set = new Set();
|
|
11
|
+
/**
|
|
12
|
+
* To call while still in the safe window where no other code
|
|
13
|
+
* has been evaluated and only before we're about to actually start the App.
|
|
14
|
+
*/
|
|
15
|
+
function iframeMessageProtection_captureAndLockBuiltins() {
|
|
11
16
|
capturedApis = {
|
|
12
17
|
setItem: Storage.prototype.setItem,
|
|
13
18
|
sessionStorage: window.sessionStorage,
|
|
14
19
|
setTimeout: window.setTimeout,
|
|
20
|
+
clearTimeout: window.clearTimeout,
|
|
15
21
|
alert: window.alert
|
|
16
22
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
// Ensure, at least from main window we cannot simply write on the public key.
|
|
24
|
+
{
|
|
25
|
+
const setItem_protected = function setItem(key, value) {
|
|
26
|
+
if (key.startsWith(SESSION_STORAGE_PREFIX)) {
|
|
27
|
+
throw new Error("Attack prevented by oidc-spa. You have malicious code running in your system");
|
|
28
|
+
}
|
|
29
|
+
(0, assert_1.assert)(capturedApis !== undefined);
|
|
30
|
+
return capturedApis.setItem.call(this, key, value);
|
|
31
|
+
};
|
|
32
|
+
{
|
|
33
|
+
const pd = Object.getOwnPropertyDescriptor(Storage.prototype, "setItem");
|
|
34
|
+
(0, assert_1.assert)(pd !== undefined);
|
|
35
|
+
Object.defineProperty(Storage.prototype, "setItem", {
|
|
36
|
+
enumerable: pd.enumerable,
|
|
37
|
+
writable: pd.writable,
|
|
38
|
+
value: setItem_protected
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
window.clearTimeout = function clearTimeout(timer) {
|
|
43
|
+
for (const getProtectedTimer of getProtectedTimer_set) {
|
|
44
|
+
const timer_protected = getProtectedTimer();
|
|
45
|
+
if (timer_protected === undefined) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (timer_protected === timer) {
|
|
49
|
+
// Probably an attack but potentially not so avoiding hard crash
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
23
52
|
}
|
|
24
53
|
(0, assert_1.assert)(capturedApis !== undefined);
|
|
25
|
-
|
|
54
|
+
capturedApis.clearTimeout.call(window, timer);
|
|
26
55
|
};
|
|
27
|
-
{
|
|
28
|
-
const pd = Object.getOwnPropertyDescriptor(Storage.prototype, "setItem");
|
|
29
|
-
(0, assert_1.assert)(pd !== undefined);
|
|
30
|
-
Object.defineProperty(Storage.prototype, "setItem", {
|
|
31
|
-
enumerable: pd.enumerable,
|
|
32
|
-
writable: pd.writable,
|
|
33
|
-
value: setItem_protected
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
56
|
}
|
|
37
57
|
function getSessionStorageKey(params) {
|
|
38
58
|
const { stateUrlParamValue } = params;
|
|
@@ -57,6 +77,8 @@ async function initIframeMessageProtection(params) {
|
|
|
57
77
|
const { publicKey, privateKey } = await (0, asymmetricEncryption_1.generateKeys)();
|
|
58
78
|
const sessionStorageKey = getSessionStorageKey({ stateUrlParamValue });
|
|
59
79
|
let timer = undefined;
|
|
80
|
+
const getProtectedTimer = () => timer;
|
|
81
|
+
getProtectedTimer_set.add(getProtectedTimer);
|
|
60
82
|
function setSessionStoragePublicKey() {
|
|
61
83
|
(0, assert_1.assert)(capturedApis !== undefined);
|
|
62
84
|
const { setItem } = capturedApis;
|
|
@@ -95,8 +117,11 @@ async function initIframeMessageProtection(params) {
|
|
|
95
117
|
return { authResponse };
|
|
96
118
|
}
|
|
97
119
|
function clearSessionStoragePublicKey() {
|
|
120
|
+
(0, assert_1.assert)(capturedApis !== undefined);
|
|
121
|
+
const { clearTimeout } = capturedApis;
|
|
98
122
|
sessionStorage.removeItem(sessionStorageKey);
|
|
99
123
|
clearTimeout(timer);
|
|
124
|
+
getProtectedTimer_set.delete(getProtectedTimer);
|
|
100
125
|
}
|
|
101
126
|
return {
|
|
102
127
|
getIsReadyToReadPublicKeyMessage,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframeMessageProtection.js","sourceRoot":"","sources":["../src/core/iframeMessageProtection.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"iframeMessageProtection.js","sourceRoot":"","sources":["../src/core/iframeMessageProtection.ts"],"names":[],"mappings":";;AAsBA,wGAoDC;AA6BD,kEAsFC;AAED,8EA2BC;AA1ND,kDAA+C;AAC/C,wEAAmG;AAGnG,IAAI,YAAY,GAQE,SAAS,CAAC;AAE5B,MAAM,sBAAsB,GAAG,yCAAyC,CAAC;AAEzE,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAA4B,CAAC;AAElE;;;GAGG;AACH,SAAgB,8CAA8C;IAC1D,YAAY,GAAG;QACX,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,OAAO;QAClC,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,KAAK,EAAE,MAAM,CAAC,KAAK;KACtB,CAAC;IAEF,8EAA8E;IAC9E,CAAC;QACG,MAAM,iBAAiB,GAAG,SAAS,OAAO,CAAY,GAAW,EAAE,KAAa;YAC5E,IAAI,GAAG,CAAC,UAAU,CAAC,sBAAsB,CAAC,EAAE,CAAC;gBACzC,MAAM,IAAI,KAAK,CACX,8EAA8E,CACjF,CAAC;YACN,CA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AAE,CAAC;IAEpH,MAAM,CAAC,WAAW,CAAC,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC1D,CAAC"}
|
package/esm/core/createOidc.js
CHANGED
|
@@ -34,7 +34,7 @@ import { evtIsThereMoreThanOneInstanceThatCantUserIframes, notifyNewInstanceThat
|
|
|
34
34
|
import { getDesiredPostLoginRedirectUrl } from "./desiredPostLoginRedirectUrl";
|
|
35
35
|
import { getHomeAndRedirectUri } from "./homeAndRedirectUri";
|
|
36
36
|
// NOTE: Replaced at build time
|
|
37
|
-
const VERSION = "8.2.
|
|
37
|
+
const VERSION = "8.2.12";
|
|
38
38
|
const globalContext = {
|
|
39
39
|
prOidcByConfigId: new Map(),
|
|
40
40
|
hasLogoutBeenCalled: id(false)
|
package/esm/core/earlyInit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getStateData, getIsStatQueryParamValue } from "./StateData";
|
|
2
2
|
import { assert } from "../tools/tsafe/assert";
|
|
3
|
-
import {
|
|
3
|
+
import { iframeMessageProtection_captureAndLockBuiltins, postEncryptedAuthResponseToParent } from "./iframeMessageProtection";
|
|
4
4
|
import { setOidcRequiredPostHydrationReplaceNavigationUrl } from "./requiredPostHydrationReplaceNavigationUrl";
|
|
5
5
|
import { setBASE_URL } from "./BASE_URL";
|
|
6
6
|
import { resolvePrShouldLoadApp } from "./prShouldLoadApp";
|
|
@@ -14,7 +14,6 @@ export function oidcEarlyInit(params) {
|
|
|
14
14
|
if (!isBrowser) {
|
|
15
15
|
return { shouldLoadApp: true };
|
|
16
16
|
}
|
|
17
|
-
captureApisForIframeProtection();
|
|
18
17
|
const { freezeFetch, freezeXMLHttpRequest, freezeWebSocket = false, isPostLoginRedirectManual = false, BASE_URL } = params;
|
|
19
18
|
const { shouldLoadApp } = handleOidcCallback({ isPostLoginRedirectManual });
|
|
20
19
|
if (shouldLoadApp) {
|
|
@@ -50,10 +49,10 @@ export function oidcEarlyInit(params) {
|
|
|
50
49
|
value: WebSocket_trusted
|
|
51
50
|
});
|
|
52
51
|
}
|
|
53
|
-
preventSessionStorageSetItemOfPublicKeyByThirdParty();
|
|
54
52
|
if (BASE_URL !== undefined) {
|
|
55
53
|
setBASE_URL({ BASE_URL });
|
|
56
54
|
}
|
|
55
|
+
iframeMessageProtection_captureAndLockBuiltins();
|
|
57
56
|
}
|
|
58
57
|
resolvePrShouldLoadApp({ shouldLoadApp });
|
|
59
58
|
return { shouldLoadApp };
|
|
@@ -149,6 +148,7 @@ function handleOidcCallback(params) {
|
|
|
149
148
|
})();
|
|
150
149
|
if (isPostLoginRedirectManual) {
|
|
151
150
|
setOidcRequiredPostHydrationReplaceNavigationUrl({ rootRelativeRedirectUrl });
|
|
151
|
+
history.replaceState({}, "", rootRelativeOriginalLocationHref);
|
|
152
152
|
}
|
|
153
153
|
else {
|
|
154
154
|
history.replaceState({}, "", rootRelativeRedirectUrl);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"earlyInit.js","sourceRoot":"","sources":["../../src/core/earlyInit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,MAAM,EAAe,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EACH,
|
|
1
|
+
{"version":3,"file":"earlyInit.js","sourceRoot":"","sources":["../../src/core/earlyInit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,MAAM,EAAe,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EACH,8CAA8C,EAC9C,iCAAiC,EACpC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,gDAAgD,EAAE,MAAM,6CAA6C,CAAC;AAC/G,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAA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+
* has been evaluated and only before we're about to actually start the App.
|
|
5
|
+
*/
|
|
6
|
+
export declare function iframeMessageProtection_captureAndLockBuiltins(): void;
|
|
4
7
|
declare function getIsEncryptedAuthResponse(params: {
|
|
5
8
|
message: unknown;
|
|
6
9
|
stateUrlParamValue: string;
|