@seip/bluebird-js 0.0.1 → 0.1.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/.env_example +53 -53
- package/AGENTS.md +426 -403
- package/LICENSE +1 -1
- package/README.md +292 -285
- package/app/routes/api.js +50 -50
- package/app/routes/web.js +55 -53
- package/app/views/about.js +63 -0
- package/app/views/dashboard.js +147 -0
- package/app/views/index.js +80 -0
- package/app/views/layouts/main/view.js +81 -0
- package/app/views/legal/terms.html +19 -0
- package/app/views/login.js +80 -0
- package/core/app.d.ts +18 -18
- package/core/app.js +684 -644
- package/core/auth.d.ts +13 -13
- package/core/auth.js +326 -326
- package/core/cache.d.ts +17 -17
- package/core/cache.js +475 -475
- package/core/cli/doctor.js +287 -287
- package/core/cli/ecosystem.js +162 -162
- package/core/cli/init.js +779 -779
- package/core/cli/migrate.js +541 -541
- package/core/cli/model.js +66 -66
- package/core/cli/nginx.js +199 -199
- package/core/cli/route.js +120 -120
- package/core/cli/view.js +55 -36
- package/core/config.d.ts +3 -3
- package/core/config.js +111 -111
- package/core/csrf.d.ts +3 -3
- package/core/csrf.js +114 -114
- package/core/database.d.ts +15 -15
- package/core/database.js +636 -636
- package/core/debug.d.ts +3 -3
- package/core/debug.js +249 -249
- package/core/hash.d.ts +3 -3
- package/core/hash.js +194 -194
- package/core/html.d.ts +42 -0
- package/core/html.js +217 -0
- package/core/index.d.ts +1176 -1071
- package/core/logger.d.ts +3 -3
- package/core/logger.js +127 -124
- package/core/middleware.d.ts +3 -3
- package/core/middleware.js +28 -28
- package/core/model.d.ts +19 -19
- package/core/model.js +600 -600
- package/core/queue.d.ts +13 -13
- package/core/queue.js +172 -172
- package/core/ratelimit.d.ts +3 -3
- package/core/ratelimit.js +145 -145
- package/core/redis.d.ts +21 -21
- package/core/redis.js +230 -230
- package/core/render-cache.js +212 -0
- package/core/render.d.ts +3 -3
- package/core/render.js +199 -555
- package/core/router.d.ts +3 -3
- package/core/router.js +171 -171
- package/core/seo.d.ts +3 -3
- package/core/seo.js +106 -106
- package/core/swagger.d.ts +3 -3
- package/core/swagger.js +60 -60
- package/core/upload.d.ts +13 -13
- package/core/upload.js +102 -102
- package/core/util/colors.js +82 -82
- package/core/validate.d.ts +15 -15
- package/core/validate.js +364 -364
- package/core/view-loader.js +162 -0
- package/core/vite.d.ts +3 -3
- package/core/vite.js +145 -145
- package/core/ws.d.ts +13 -13
- package/core/ws.js +245 -245
- package/index.js +18 -18
- package/jsconfig.json +15 -15
- package/package.json +85 -86
- package/production.md +273 -273
- package/public/css/bluebird.min.css +1 -1
- package/public/js/bluebird-client.js +1780 -1662
- package/public/js/bluebird.min.js +1072 -1072
- package/app/views/about.html +0 -161
- package/app/views/dashboard.html +0 -140
- package/app/views/index.html +0 -150
- package/app/views/login.html +0 -144
package/core/csrf.js
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
-
import Config from "./config.js";
|
|
3
|
-
|
|
4
|
-
const propsConfig = Config.props();
|
|
5
|
-
const defaultSecret = propsConfig.jwtSecret || "bluebird-csrf-secret-key-32-chars!";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Native CSRF protection module using HMAC-SHA256 signed tokens without external dependencies.
|
|
9
|
-
*/
|
|
10
|
-
class Csrf {
|
|
11
|
-
/**
|
|
12
|
-
* Generates a signed CSRF token string.
|
|
13
|
-
* @param {string} [secret] - Secret key used for signing.
|
|
14
|
-
* @returns {string} Hex encoded token in format salt.timestamp.signature.
|
|
15
|
-
*/
|
|
16
|
-
static generateToken(secret = process.env.JWT_SECRET || defaultSecret) {
|
|
17
|
-
const salt = randomBytes(16).toString("hex");
|
|
18
|
-
const timestamp = Date.now().toString(36);
|
|
19
|
-
const signature = createHmac("sha256", secret)
|
|
20
|
-
.update(`${salt}.${timestamp}`)
|
|
21
|
-
.digest("hex");
|
|
22
|
-
|
|
23
|
-
return `${salt}.${timestamp}.${signature}`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Verifies the authenticity and validity of a CSRF token.
|
|
28
|
-
* @param {string} token - The CSRF token to verify.
|
|
29
|
-
* @param {string} [secret] - Secret key used for verification.
|
|
30
|
-
* @param {number} [maxAgeMs=86400000] - Maximum token age in milliseconds (default 24h).
|
|
31
|
-
* @returns {boolean} True if the token is valid.
|
|
32
|
-
*/
|
|
33
|
-
static verifyToken(token, secret = process.env.JWT_SECRET || defaultSecret, maxAgeMs = 86400000) {
|
|
34
|
-
if (!token || typeof token !== "string") return false;
|
|
35
|
-
|
|
36
|
-
const parts = token.split(".");
|
|
37
|
-
if (parts.length !== 3) return false;
|
|
38
|
-
|
|
39
|
-
const [salt, timestampStr, signature] = parts;
|
|
40
|
-
const timestamp = parseInt(timestampStr, 36);
|
|
41
|
-
|
|
42
|
-
if (isNaN(timestamp) || Date.now() - timestamp > maxAgeMs) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const expected = createHmac("sha256", secret)
|
|
47
|
-
.update(`${salt}.${timestampStr}`)
|
|
48
|
-
.digest("hex");
|
|
49
|
-
|
|
50
|
-
const sigBuf = Buffer.from(signature);
|
|
51
|
-
const expBuf = Buffer.from(expected);
|
|
52
|
-
|
|
53
|
-
if (sigBuf.length !== expBuf.length) return false;
|
|
54
|
-
return timingSafeEqual(sigBuf, expBuf);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Express middleware that ensures valid CSRF tokens on mutating HTTP requests.
|
|
59
|
-
* @param {Object} [options={}] - Configuration options.
|
|
60
|
-
* @param {string} [options.cookieName="_csrf"] - Name of the cookie storing the CSRF token.
|
|
61
|
-
* @param {string} [options.headerName="x-csrf-token"] - Name of the request header.
|
|
62
|
-
* @param {string} [options.bodyKey="_csrf"] - Name of the body field.
|
|
63
|
-
* @param {number} [options.maxAgeMs=86400000] - Token expiration in milliseconds.
|
|
64
|
-
* @returns {Function} Express middleware.
|
|
65
|
-
*/
|
|
66
|
-
static middleware(options = {}) {
|
|
67
|
-
const cookieName = options.cookieName || "_csrf";
|
|
68
|
-
const headerName = (options.headerName || "x-csrf-token").toLowerCase();
|
|
69
|
-
const bodyKey = options.bodyKey || "_csrf";
|
|
70
|
-
const maxAgeMs = options.maxAgeMs || 86400000;
|
|
71
|
-
const secret = options.secret || process.env.JWT_SECRET || defaultSecret;
|
|
72
|
-
|
|
73
|
-
return (req, res, next) => {
|
|
74
|
-
let token = req.cookies?.[cookieName];
|
|
75
|
-
|
|
76
|
-
if (!token || !Csrf.verifyToken(token, secret, maxAgeMs)) {
|
|
77
|
-
token = Csrf.generateToken(secret);
|
|
78
|
-
if (typeof res.cookie === "function") {
|
|
79
|
-
res.cookie(cookieName, token, {
|
|
80
|
-
httpOnly: false,
|
|
81
|
-
sameSite: "lax",
|
|
82
|
-
secure: Boolean(!propsConfig.debug),
|
|
83
|
-
path: "/",
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
res.locals.csrfToken = token;
|
|
89
|
-
req.csrfToken = () => token;
|
|
90
|
-
|
|
91
|
-
const safeMethods = ["GET", "HEAD", "OPTIONS"];
|
|
92
|
-
if (safeMethods.includes(req.method)) {
|
|
93
|
-
return next();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const receivedToken =
|
|
97
|
-
req.headers[headerName] ||
|
|
98
|
-
req.body?.[bodyKey] ||
|
|
99
|
-
req.query?.[bodyKey];
|
|
100
|
-
|
|
101
|
-
if (!receivedToken || !Csrf.verifyToken(receivedToken, secret, maxAgeMs) || receivedToken !== token) {
|
|
102
|
-
return res.status(403).json({
|
|
103
|
-
status: "error",
|
|
104
|
-
message: "Invalid or missing CSRF token.",
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
next();
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export { Csrf };
|
|
114
|
-
export default Csrf;
|
|
1
|
+
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import Config from "./config.js";
|
|
3
|
+
|
|
4
|
+
const propsConfig = Config.props();
|
|
5
|
+
const defaultSecret = propsConfig.jwtSecret || "bluebird-csrf-secret-key-32-chars!";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Native CSRF protection module using HMAC-SHA256 signed tokens without external dependencies.
|
|
9
|
+
*/
|
|
10
|
+
class Csrf {
|
|
11
|
+
/**
|
|
12
|
+
* Generates a signed CSRF token string.
|
|
13
|
+
* @param {string} [secret] - Secret key used for signing.
|
|
14
|
+
* @returns {string} Hex encoded token in format salt.timestamp.signature.
|
|
15
|
+
*/
|
|
16
|
+
static generateToken(secret = process.env.JWT_SECRET || defaultSecret) {
|
|
17
|
+
const salt = randomBytes(16).toString("hex");
|
|
18
|
+
const timestamp = Date.now().toString(36);
|
|
19
|
+
const signature = createHmac("sha256", secret)
|
|
20
|
+
.update(`${salt}.${timestamp}`)
|
|
21
|
+
.digest("hex");
|
|
22
|
+
|
|
23
|
+
return `${salt}.${timestamp}.${signature}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Verifies the authenticity and validity of a CSRF token.
|
|
28
|
+
* @param {string} token - The CSRF token to verify.
|
|
29
|
+
* @param {string} [secret] - Secret key used for verification.
|
|
30
|
+
* @param {number} [maxAgeMs=86400000] - Maximum token age in milliseconds (default 24h).
|
|
31
|
+
* @returns {boolean} True if the token is valid.
|
|
32
|
+
*/
|
|
33
|
+
static verifyToken(token, secret = process.env.JWT_SECRET || defaultSecret, maxAgeMs = 86400000) {
|
|
34
|
+
if (!token || typeof token !== "string") return false;
|
|
35
|
+
|
|
36
|
+
const parts = token.split(".");
|
|
37
|
+
if (parts.length !== 3) return false;
|
|
38
|
+
|
|
39
|
+
const [salt, timestampStr, signature] = parts;
|
|
40
|
+
const timestamp = parseInt(timestampStr, 36);
|
|
41
|
+
|
|
42
|
+
if (isNaN(timestamp) || Date.now() - timestamp > maxAgeMs) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const expected = createHmac("sha256", secret)
|
|
47
|
+
.update(`${salt}.${timestampStr}`)
|
|
48
|
+
.digest("hex");
|
|
49
|
+
|
|
50
|
+
const sigBuf = Buffer.from(signature);
|
|
51
|
+
const expBuf = Buffer.from(expected);
|
|
52
|
+
|
|
53
|
+
if (sigBuf.length !== expBuf.length) return false;
|
|
54
|
+
return timingSafeEqual(sigBuf, expBuf);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Express middleware that ensures valid CSRF tokens on mutating HTTP requests.
|
|
59
|
+
* @param {Object} [options={}] - Configuration options.
|
|
60
|
+
* @param {string} [options.cookieName="_csrf"] - Name of the cookie storing the CSRF token.
|
|
61
|
+
* @param {string} [options.headerName="x-csrf-token"] - Name of the request header.
|
|
62
|
+
* @param {string} [options.bodyKey="_csrf"] - Name of the body field.
|
|
63
|
+
* @param {number} [options.maxAgeMs=86400000] - Token expiration in milliseconds.
|
|
64
|
+
* @returns {Function} Express middleware.
|
|
65
|
+
*/
|
|
66
|
+
static middleware(options = {}) {
|
|
67
|
+
const cookieName = options.cookieName || "_csrf";
|
|
68
|
+
const headerName = (options.headerName || "x-csrf-token").toLowerCase();
|
|
69
|
+
const bodyKey = options.bodyKey || "_csrf";
|
|
70
|
+
const maxAgeMs = options.maxAgeMs || 86400000;
|
|
71
|
+
const secret = options.secret || process.env.JWT_SECRET || defaultSecret;
|
|
72
|
+
|
|
73
|
+
return (req, res, next) => {
|
|
74
|
+
let token = req.cookies?.[cookieName];
|
|
75
|
+
|
|
76
|
+
if (!token || !Csrf.verifyToken(token, secret, maxAgeMs)) {
|
|
77
|
+
token = Csrf.generateToken(secret);
|
|
78
|
+
if (typeof res.cookie === "function") {
|
|
79
|
+
res.cookie(cookieName, token, {
|
|
80
|
+
httpOnly: false,
|
|
81
|
+
sameSite: "lax",
|
|
82
|
+
secure: Boolean(!propsConfig.debug),
|
|
83
|
+
path: "/",
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
res.locals.csrfToken = token;
|
|
89
|
+
req.csrfToken = () => token;
|
|
90
|
+
|
|
91
|
+
const safeMethods = ["GET", "HEAD", "OPTIONS"];
|
|
92
|
+
if (safeMethods.includes(req.method)) {
|
|
93
|
+
return next();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const receivedToken =
|
|
97
|
+
req.headers[headerName] ||
|
|
98
|
+
req.body?.[bodyKey] ||
|
|
99
|
+
req.query?.[bodyKey];
|
|
100
|
+
|
|
101
|
+
if (!receivedToken || !Csrf.verifyToken(receivedToken, secret, maxAgeMs) || receivedToken !== token) {
|
|
102
|
+
return res.status(403).json({
|
|
103
|
+
status: "error",
|
|
104
|
+
message: "Invalid or missing CSRF token.",
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
next();
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { Csrf };
|
|
114
|
+
export default Csrf;
|
package/core/database.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Database,
|
|
3
|
-
DB_TYPE,
|
|
4
|
-
DatabaseQueryOptions,
|
|
5
|
-
DatabaseTransactionClient,
|
|
6
|
-
PaginatedResult,
|
|
7
|
-
} from "./index.js";
|
|
8
|
-
export default Database;
|
|
9
|
-
export {
|
|
10
|
-
Database,
|
|
11
|
-
DB_TYPE,
|
|
12
|
-
DatabaseQueryOptions,
|
|
13
|
-
DatabaseTransactionClient,
|
|
14
|
-
PaginatedResult,
|
|
15
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
Database,
|
|
3
|
+
DB_TYPE,
|
|
4
|
+
DatabaseQueryOptions,
|
|
5
|
+
DatabaseTransactionClient,
|
|
6
|
+
PaginatedResult,
|
|
7
|
+
} from "./index.js";
|
|
8
|
+
export default Database;
|
|
9
|
+
export {
|
|
10
|
+
Database,
|
|
11
|
+
DB_TYPE,
|
|
12
|
+
DatabaseQueryOptions,
|
|
13
|
+
DatabaseTransactionClient,
|
|
14
|
+
PaginatedResult,
|
|
15
|
+
};
|