flowlink-auth 2.6.9
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/AuthClient.js +2822 -0
- package/dist/ErrorBox.js +1042 -0
- package/dist/Protected.js +2628 -0
- package/dist/SignIn.js +1192 -0
- package/dist/SignUp.js +1246 -0
- package/dist/api.js +55 -0
- package/dist/createAuthMiddleware.js +5949 -0
- package/dist/index.js +574 -0
- package/dist/init.js +73 -0
- package/dist/provider.js +1234 -0
- package/dist/securityUtils.js +102 -0
- package/dist/useAuth.js +1057 -0
- package/package.json +31 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// src/securityUtils.js
|
|
2
|
+
function sanitizeInput(input) {
|
|
3
|
+
if (typeof input !== "string") return input;
|
|
4
|
+
const div = document.createElement("div");
|
|
5
|
+
div.textContent = input;
|
|
6
|
+
return div.innerHTML;
|
|
7
|
+
}
|
|
8
|
+
function validateEmail(email) {
|
|
9
|
+
if (typeof email !== "string") return false;
|
|
10
|
+
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
11
|
+
return regex.test(email) && email.length <= 255;
|
|
12
|
+
}
|
|
13
|
+
function validatePasswordStrength(password) {
|
|
14
|
+
if (typeof password !== "string") return false;
|
|
15
|
+
if (password.length < 12) return false;
|
|
16
|
+
const hasUpper = /[A-Z]/.test(password);
|
|
17
|
+
const hasLower = /[a-z]/.test(password);
|
|
18
|
+
const hasNumber = /[0-9]/.test(password);
|
|
19
|
+
const hasSpecial = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password);
|
|
20
|
+
return hasUpper && hasLower && hasNumber && hasSpecial;
|
|
21
|
+
}
|
|
22
|
+
function getPasswordFeedback(password) {
|
|
23
|
+
const feedback = [];
|
|
24
|
+
if (password.length < 12) {
|
|
25
|
+
feedback.push("At least 12 characters");
|
|
26
|
+
}
|
|
27
|
+
if (!/[A-Z]/.test(password)) {
|
|
28
|
+
feedback.push("One uppercase letter");
|
|
29
|
+
}
|
|
30
|
+
if (!/[a-z]/.test(password)) {
|
|
31
|
+
feedback.push("One lowercase letter");
|
|
32
|
+
}
|
|
33
|
+
if (!/[0-9]/.test(password)) {
|
|
34
|
+
feedback.push("One number");
|
|
35
|
+
}
|
|
36
|
+
if (!/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password)) {
|
|
37
|
+
feedback.push("One special character");
|
|
38
|
+
}
|
|
39
|
+
return feedback;
|
|
40
|
+
}
|
|
41
|
+
function isSecureContext() {
|
|
42
|
+
if (typeof window === "undefined") return true;
|
|
43
|
+
const isLocalhost = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname === "[::1]";
|
|
44
|
+
const isHttps = window.location.protocol === "https:";
|
|
45
|
+
return isHttps || isLocalhost;
|
|
46
|
+
}
|
|
47
|
+
function checkSecureContext() {
|
|
48
|
+
if (!isSecureContext()) {
|
|
49
|
+
console.warn(
|
|
50
|
+
"flowlink-auth: HTTPS is required for production. Your connection is not secure. Authentication may fail."
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function getSafeErrorMessage(error) {
|
|
55
|
+
if (typeof error === "string") {
|
|
56
|
+
if (error.includes("password") || error.includes("token") || error.includes("secret")) {
|
|
57
|
+
return "An error occurred. Please try again.";
|
|
58
|
+
}
|
|
59
|
+
return error;
|
|
60
|
+
}
|
|
61
|
+
if (error?.message) {
|
|
62
|
+
return getSafeErrorMessage(error.message);
|
|
63
|
+
}
|
|
64
|
+
return "An error occurred. Please try again.";
|
|
65
|
+
}
|
|
66
|
+
function generateNonce() {
|
|
67
|
+
const array = new Uint8Array(16);
|
|
68
|
+
if (typeof window !== "undefined" && window.crypto) {
|
|
69
|
+
window.crypto.getRandomValues(array);
|
|
70
|
+
}
|
|
71
|
+
return Array.from(array, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
72
|
+
}
|
|
73
|
+
function validateOrigin(expectedOrigin) {
|
|
74
|
+
if (typeof window === "undefined") return true;
|
|
75
|
+
const currentOrigin = window.location.origin;
|
|
76
|
+
return currentOrigin === expectedOrigin;
|
|
77
|
+
}
|
|
78
|
+
function hasXSSPatterns(input) {
|
|
79
|
+
if (typeof input !== "string") return false;
|
|
80
|
+
const xssPatterns = [
|
|
81
|
+
/<script[^>]*>.*?<\/script>/gi,
|
|
82
|
+
/javascript:/gi,
|
|
83
|
+
/on\w+\s*=/gi,
|
|
84
|
+
/<iframe/gi,
|
|
85
|
+
/<object/gi,
|
|
86
|
+
/<embed/gi
|
|
87
|
+
];
|
|
88
|
+
return xssPatterns.some((pattern) => pattern.test(input));
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
checkSecureContext,
|
|
92
|
+
generateNonce,
|
|
93
|
+
getPasswordFeedback,
|
|
94
|
+
getSafeErrorMessage,
|
|
95
|
+
hasXSSPatterns,
|
|
96
|
+
isSecureContext,
|
|
97
|
+
sanitizeInput,
|
|
98
|
+
validateEmail,
|
|
99
|
+
validateOrigin,
|
|
100
|
+
validatePasswordStrength
|
|
101
|
+
};
|
|
102
|
+
|