@chemmangat/msal-next 3.0.3 → 3.0.4
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/dist/chunk-AD43IVG7.mjs +51 -0
- package/dist/index.d.mts +914 -1
- package/dist/index.d.ts +914 -1
- package/dist/index.js +1686 -1
- package/dist/index.mjs +1595 -0
- package/dist/server.js +115 -1
- package/dist/server.mjs +72 -1
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/utils/validation.ts
|
|
2
|
+
function safeJsonParse(jsonString, validator) {
|
|
3
|
+
try {
|
|
4
|
+
const parsed = JSON.parse(jsonString);
|
|
5
|
+
if (validator(parsed)) {
|
|
6
|
+
return parsed;
|
|
7
|
+
}
|
|
8
|
+
console.warn("[Validation] JSON validation failed");
|
|
9
|
+
return null;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error("[Validation] JSON parse error:", error);
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function isValidAccountData(data) {
|
|
16
|
+
return typeof data === "object" && data !== null && typeof data.homeAccountId === "string" && data.homeAccountId.length > 0 && typeof data.username === "string" && data.username.length > 0 && (data.name === void 0 || typeof data.name === "string");
|
|
17
|
+
}
|
|
18
|
+
function sanitizeError(error) {
|
|
19
|
+
if (error instanceof Error) {
|
|
20
|
+
const message = error.message;
|
|
21
|
+
const sanitized = message.replace(/[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}/g, "[TOKEN_REDACTED]").replace(/[a-f0-9]{32,}/gi, "[SECRET_REDACTED]").replace(/Bearer\s+[^\s]+/gi, "Bearer [REDACTED]");
|
|
22
|
+
return sanitized;
|
|
23
|
+
}
|
|
24
|
+
return "An unexpected error occurred";
|
|
25
|
+
}
|
|
26
|
+
function isValidRedirectUri(uri, allowedOrigins) {
|
|
27
|
+
try {
|
|
28
|
+
const url = new URL(uri);
|
|
29
|
+
return allowedOrigins.some((allowed) => {
|
|
30
|
+
const allowedUrl = new URL(allowed);
|
|
31
|
+
return url.origin === allowedUrl.origin;
|
|
32
|
+
});
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function isValidScope(scope) {
|
|
38
|
+
return /^[a-zA-Z0-9._-]+$/.test(scope);
|
|
39
|
+
}
|
|
40
|
+
function validateScopes(scopes) {
|
|
41
|
+
return Array.isArray(scopes) && scopes.every(isValidScope);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
safeJsonParse,
|
|
46
|
+
isValidAccountData,
|
|
47
|
+
sanitizeError,
|
|
48
|
+
isValidRedirectUri,
|
|
49
|
+
isValidScope,
|
|
50
|
+
validateScopes
|
|
51
|
+
};
|