@blackbelt-technology/pi-dashboard-client-utils 0.10.0 → 0.11.0
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/package.json +3 -3
- package/src/identity/login-flow.ts +33 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackbelt-technology/pi-dashboard-client-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Small reusable React components, hooks, and helpers shared between the pi-dashboard shell and dashboard plugins. Per-subpath exports; no markdown stack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -159,8 +159,8 @@
|
|
|
159
159
|
"react-dom": ">=18.0.0"
|
|
160
160
|
},
|
|
161
161
|
"dependencies": {
|
|
162
|
-
"@blackbelt-technology/dashboard-plugin-runtime": "^0.
|
|
163
|
-
"@blackbelt-technology/pi-dashboard-shared": "^0.
|
|
162
|
+
"@blackbelt-technology/dashboard-plugin-runtime": "^0.11.0",
|
|
163
|
+
"@blackbelt-technology/pi-dashboard-shared": "^0.11.0",
|
|
164
164
|
"@mdi/js": "^7.4.47",
|
|
165
165
|
"@mdi/react": "^1.6.1"
|
|
166
166
|
},
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
* (B4/LG-19): a plain bearer is stored, no key is persisted across the redirect.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
+
import { classifyUrl } from "@blackbelt-technology/pi-dashboard-shared/url-policy.js";
|
|
28
29
|
import { buildAuthorizeRequest, exchangeCode, type OidcClientConfig } from "./oidc-flow.js";
|
|
29
30
|
import { clearAccessToken, getIdToken, setAccessToken, setIdToken } from "./token-store.js";
|
|
30
31
|
|
|
@@ -74,6 +75,29 @@ export class LoginFlowError extends Error {
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Discovery endpoints come from a fetched document, so they are untrusted
|
|
80
|
+
* navigation / fetch targets (harden-client-sinks D11): `https:` anywhere, or
|
|
81
|
+
* `http:` on a loopback host only. Classified with `origin = null` because the
|
|
82
|
+
* endpoints are absolute.
|
|
83
|
+
*/
|
|
84
|
+
function isAllowedOidcEndpoint(raw: unknown): boolean {
|
|
85
|
+
const cls = classifyUrl(raw, null);
|
|
86
|
+
if (cls === "loopback") return true;
|
|
87
|
+
if (cls !== "external") return false;
|
|
88
|
+
try {
|
|
89
|
+
return new URL((raw as string).trim()).protocol === "https:";
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function assertDiscoveryEndpoints(disc: Discovery, keys: readonly (keyof Discovery)[]): void {
|
|
96
|
+
for (const k of keys) {
|
|
97
|
+
if (!isAllowedOidcEndpoint(disc[k])) throw new Error(`disallowed ${k}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
77
101
|
async function fetchJson<T>(url: string): Promise<T> {
|
|
78
102
|
const res = await fetch(url);
|
|
79
103
|
if (!res.ok) throw new Error(`fetch failed: ${res.status}`);
|
|
@@ -94,6 +118,12 @@ export async function beginLogin(returnTo: string): Promise<void> {
|
|
|
94
118
|
disc = await fetchJson<Discovery>(
|
|
95
119
|
`${cfg.issuer.replace(/\/+$/, "")}/.well-known/openid-configuration`,
|
|
96
120
|
);
|
|
121
|
+
assertDiscoveryEndpoints(
|
|
122
|
+
disc,
|
|
123
|
+
disc.end_session_endpoint === undefined
|
|
124
|
+
? ["authorization_endpoint", "token_endpoint"]
|
|
125
|
+
: ["authorization_endpoint", "token_endpoint", "end_session_endpoint"],
|
|
126
|
+
);
|
|
97
127
|
} catch (err) {
|
|
98
128
|
throw new LoginFlowError("discovery-failed", err);
|
|
99
129
|
}
|
|
@@ -122,6 +152,7 @@ export async function beginLogin(returnTo: string): Promise<void> {
|
|
|
122
152
|
redirectUri,
|
|
123
153
|
};
|
|
124
154
|
sessionStorage.setItem(STASH_KEY, JSON.stringify(stash));
|
|
155
|
+
// client-sinks: allow — authorization_endpoint passed isAllowedOidcEndpoint (classifyUrl) above
|
|
125
156
|
window.location.assign(req.url);
|
|
126
157
|
}
|
|
127
158
|
|
|
@@ -145,6 +176,7 @@ export async function beginLogout(): Promise<void> {
|
|
|
145
176
|
`${cfg.issuer.replace(/\/+$/, "")}/.well-known/openid-configuration`,
|
|
146
177
|
);
|
|
147
178
|
if (!disc.end_session_endpoint) throw new Error("no end_session_endpoint");
|
|
179
|
+
assertDiscoveryEndpoints(disc, ["end_session_endpoint"]);
|
|
148
180
|
} catch (err) {
|
|
149
181
|
throw new LoginFlowError("discovery-failed", err);
|
|
150
182
|
}
|
|
@@ -152,6 +184,7 @@ export async function beginLogout(): Promise<void> {
|
|
|
152
184
|
url.searchParams.set("client_id", cfg.clientId);
|
|
153
185
|
url.searchParams.set("post_logout_redirect_uri", `${window.location.origin}/`);
|
|
154
186
|
if (idToken) url.searchParams.set("id_token_hint", idToken);
|
|
187
|
+
// client-sinks: allow — end_session_endpoint passed isAllowedOidcEndpoint (classifyUrl) above
|
|
155
188
|
window.location.assign(url.toString());
|
|
156
189
|
}
|
|
157
190
|
|