webspresso 0.0.103 → 0.0.105
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/.agents/AGENTS.md +6 -0
- package/.agents/ARCHITECTURE.md +23 -0
- package/.agents/CACHE.md +147 -0
- package/.agents/CLI.md +1 -1
- package/.agents/EARLY_HINTS.md +120 -0
- package/.agents/HEALTH.md +118 -0
- package/.agents/LIMITS.md +109 -0
- package/.agents/ORM.md +155 -1
- package/.agents/PLUGINS.md +28 -0
- package/.agents/RESILIENCE.md +235 -0
- package/AGENTS.md +6 -0
- package/README.md +2 -2
- package/bin/commands/add-docker.js +6 -6
- package/bin/commands/dev.js +4 -3
- package/bin/commands/new.js +5 -5
- package/bin/commands/openapi.js +1 -1
- package/bin/commands/start.js +1 -1
- package/bin/utils/orm-map-html.js +2 -8
- package/bin/utils/project.js +2 -2
- package/core/auth/hash.js +5 -4
- package/core/auth/jwt.js +6 -57
- package/core/auth/magic-link.js +4 -5
- package/core/auth/manager.js +3 -5
- package/core/auth/oauth.js +45 -30
- package/core/auth/totp.js +5 -16
- package/core/auth/user-agent.js +1 -21
- package/core/cache/byte-size.js +123 -0
- package/core/cache/index.js +21 -0
- package/core/cache/lru.js +477 -0
- package/core/cache/tagged-lru.js +346 -0
- package/core/commands/registry.js +6 -20
- package/core/content/renderer.js +1 -13
- package/core/early-hints/index.js +267 -0
- package/core/errors/domain.js +48 -0
- package/core/errors/http.js +31 -0
- package/core/errors/index.js +10 -0
- package/core/errors/middleware.js +2 -8
- package/core/errors/normalize.js +88 -2
- package/core/events/discovery.js +6 -24
- package/core/events/dispatcher.js +2 -7
- package/core/forms/form-builder.js +1 -9
- package/core/health/index.js +41 -0
- package/core/health/middleware.js +213 -0
- package/core/health/normalize.js +140 -0
- package/core/health/probes.js +203 -0
- package/core/limits/index.js +34 -0
- package/core/limits/middleware.js +317 -0
- package/core/limits/normalize.js +222 -0
- package/core/orm/batch.js +70 -0
- package/core/orm/cache/fingerprint.js +2 -2
- package/core/orm/cache/memory-provider.js +27 -110
- package/core/orm/index.js +76 -8
- package/core/orm/json-fields.js +22 -8
- package/core/orm/model.js +10 -0
- package/core/orm/query-builder.js +63 -9
- package/core/orm/query-filters.js +393 -0
- package/core/orm/repository.js +318 -19
- package/core/orm/schema-helpers.js +8 -10
- package/core/orm/scopes.js +321 -1
- package/core/orm/transaction.js +10 -2
- package/core/orm/utils.js +4 -86
- package/core/queue/adapters/database.js +4 -8
- package/core/queue/manager.js +55 -41
- package/core/resilience/circuit-breaker.js +391 -0
- package/core/resilience/errors.js +63 -0
- package/core/resilience/index.js +53 -0
- package/core/resilience/registry.js +97 -0
- package/core/resilience/retry.js +203 -0
- package/core/schema-cache.js +9 -2
- package/core/shutdown/http-adapter.js +4 -1
- package/core/shutdown/shutdown-manager.js +132 -31
- package/core/utils/array.js +12 -0
- package/core/utils/base64url.js +8 -0
- package/core/utils/crypto.js +191 -0
- package/core/utils/ensure-leading-slash.js +6 -0
- package/core/utils/escape-html.js +7 -0
- package/core/utils/escape-regexp.js +7 -0
- package/core/utils/fetch.js +121 -0
- package/core/utils/fs.js +144 -0
- package/core/utils/get-client-ip.js +6 -0
- package/core/utils/hmac.js +6 -0
- package/core/utils/html.js +72 -0
- package/core/utils/ip.js +86 -0
- package/core/utils/json.js +98 -0
- package/core/utils/object.js +106 -0
- package/core/utils/random.js +9 -0
- package/core/utils/regex.js +77 -0
- package/core/utils/safe-compare.js +3 -0
- package/core/utils/sha256.js +6 -0
- package/core/utils/string.js +87 -0
- package/core/utils/strip-trailing-slash.js +6 -0
- package/core/utils/time.js +96 -0
- package/core/utils/timeout.js +348 -0
- package/core/utils/url.js +106 -0
- package/core/utils/walk.js +7 -0
- package/index.d.ts +627 -2
- package/index.js +158 -0
- package/package.json +1 -2
- package/plugins/admin-panel/auth.js +15 -7
- package/plugins/admin-panel/client/parts/01-state-api-breadcrumb.js +82 -10
- package/plugins/admin-panel/client/parts/05-rich-text-file-helpers.js +4 -2
- package/plugins/admin-panel/client/parts/08-record-list.js +3 -2
- package/plugins/admin-panel/client/parts/10-export-registry.js +6 -0
- package/plugins/admin-panel/core/api-extensions.js +3 -80
- package/plugins/admin-panel/index.js +1 -1
- package/plugins/admin-panel/lib/login-rate-limiter.js +15 -13
- package/plugins/admin-panel/modules/menu.js +1 -1
- package/plugins/api-key/crypto.js +3 -26
- package/plugins/api-key/scopes.js +5 -7
- package/plugins/audit-log/api-handlers.js +8 -7
- package/plugins/audit-log/middleware.js +11 -2
- package/plugins/audit-log/parse.js +3 -3
- package/plugins/basic-auth/index.js +2 -26
- package/plugins/cors.js +2 -2
- package/plugins/csrf/index.js +7 -23
- package/plugins/dashboard/app.js +2 -2
- package/plugins/dashboard/index.js +5 -5
- package/plugins/data-exchange/record-selection.js +2 -5
- package/plugins/email/api-handlers.js +5 -18
- package/plugins/email/auth-bridge.js +3 -2
- package/plugins/file-manager/admin-component.js +3 -1
- package/plugins/file-manager/core.js +34 -4
- package/plugins/health-check.js +2 -1
- package/plugins/index.js +2 -0
- package/plugins/lazy.js +5 -6
- package/plugins/mcp/auth.js +1 -13
- package/plugins/mcp/discovery.js +18 -17
- package/plugins/mcp/index.js +23 -1
- package/plugins/mcp/transports/sse.js +10 -1
- package/plugins/orm-cache-admin/admin-component.js +3 -2
- package/plugins/polar/src/api.js +11 -3
- package/plugins/polar/src/webhooks.js +7 -13
- package/plugins/rate-limit/index.js +3 -1
- package/plugins/recaptcha/helpers.js +1 -7
- package/plugins/recaptcha/verify.js +37 -23
- package/plugins/redirect/index.js +57 -7
- package/plugins/rest-resources/index.js +1 -207
- package/plugins/rls/index.js +170 -0
- package/plugins/schema-explorer/admin-component.js +4 -2
- package/plugins/schema-explorer.js +40 -29
- package/plugins/seo-checker/index.js +5 -2
- package/plugins/site-analytics/tracking.js +21 -18
- package/plugins/sitemap.js +21 -17
- package/plugins/swagger.js +13 -17
- package/plugins/upload/index.js +4 -3
- package/plugins/upload/orphan-pruner.js +4 -3
- package/plugins/webhooks/crypto.js +6 -28
- package/plugins/webhooks/dispatcher.js +14 -9
- package/plugins/webhooks/index.js +6 -0
- package/plugins/webhooks/matcher.js +28 -17
- package/plugins/webhooks/sender.js +40 -13
- package/src/app-context.js +41 -5
- package/src/dev/banner.js +6 -2
- package/src/dev-reload/index.js +47 -6
- package/src/file-router.js +1 -3
- package/src/helpers.js +180 -33
- package/src/modules/module-discovery.js +1 -9
- package/src/pages/page-loader.js +53 -1
- package/src/plugin-manager.js +90 -17
- package/src/server.js +137 -26
- package/src/services/discovery.js +19 -40
- package/src/services/executor.js +86 -25
- package/src/services/memoize.js +3 -25
- package/src/services/registry.js +6 -0
- package/src/template/precompile.js +8 -19
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
|
+
const { safeJsonParse } = require('../../core/utils/json');
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Normalize scopes input into an array of string tokens
|
|
10
12
|
*
|
|
@@ -25,13 +27,9 @@ function normalizeScopes(scopes) {
|
|
|
25
27
|
if (typeof scopes === 'string') {
|
|
26
28
|
const trimmed = scopes.trim();
|
|
27
29
|
if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return parsed.map((s) => String(s).trim()).filter(Boolean);
|
|
32
|
-
}
|
|
33
|
-
} catch (_) {
|
|
34
|
-
// Fallback to comma-separated parsing
|
|
30
|
+
const parsed = safeJsonParse(trimmed, null);
|
|
31
|
+
if (Array.isArray(parsed)) {
|
|
32
|
+
return parsed.map((s) => String(s).trim()).filter(Boolean);
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
return trimmed
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const { purgeAuditLogs } = require('./purge');
|
|
7
|
+
const { safeJsonParse } = require('../../core/utils/json');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @param {Object} options
|
|
@@ -66,8 +67,13 @@ function createAuditLogHandlers(options) {
|
|
|
66
67
|
.offset((page - 1) * perPage)
|
|
67
68
|
.limit(perPage);
|
|
68
69
|
|
|
70
|
+
const normalizedRows = rows.map((r) => ({
|
|
71
|
+
...r,
|
|
72
|
+
metadata: safeJsonParse(r.metadata, r.metadata),
|
|
73
|
+
}));
|
|
74
|
+
|
|
69
75
|
res.json({
|
|
70
|
-
data:
|
|
76
|
+
data: normalizedRows,
|
|
71
77
|
meta: { page, perPage, total },
|
|
72
78
|
});
|
|
73
79
|
} catch (err) {
|
|
@@ -100,12 +106,7 @@ function createAuditLogHandlers(options) {
|
|
|
100
106
|
const lastModifiedEvent = rows.length > 0 ? rows[rows.length - 1] : null;
|
|
101
107
|
|
|
102
108
|
const events = rows.map((r, index) => {
|
|
103
|
-
|
|
104
|
-
if (typeof parsedMetadata === 'string') {
|
|
105
|
-
try {
|
|
106
|
-
parsedMetadata = JSON.parse(parsedMetadata);
|
|
107
|
-
} catch {}
|
|
108
|
-
}
|
|
109
|
+
const parsedMetadata = safeJsonParse(r.metadata, r.metadata);
|
|
109
110
|
|
|
110
111
|
const changedFields = Array.isArray(parsedMetadata?.changedFields)
|
|
111
112
|
? parsedMetadata.changedFields
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const { parseAdminModelAudit } = require('./parse');
|
|
7
|
+
const { getClientIp } = require('../../core/utils/ip');
|
|
7
8
|
|
|
8
9
|
function stringifyId(val) {
|
|
9
10
|
if (val === undefined || val === null) {
|
|
@@ -81,6 +82,14 @@ function createAuditMiddleware(options) {
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
const metadata = buildMetadata(action, req);
|
|
85
|
+
let metadataVal = metadata || null;
|
|
86
|
+
if (metadataVal && typeof metadataVal === 'object') {
|
|
87
|
+
const clientName = knex?.client?.config?.client || '';
|
|
88
|
+
if (typeof clientName === 'string' && clientName.includes('sqlite')) {
|
|
89
|
+
metadataVal = JSON.stringify(metadataVal);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
84
93
|
const pathStr = (req.originalUrl || req.url || req.path || '').slice(0, 2000);
|
|
85
94
|
const row = {
|
|
86
95
|
actor_id: actor.id != null ? Number(actor.id) : null,
|
|
@@ -90,9 +99,9 @@ function createAuditMiddleware(options) {
|
|
|
90
99
|
resource_id: resourceId,
|
|
91
100
|
http_method: req.method,
|
|
92
101
|
path: pathStr,
|
|
93
|
-
ip:
|
|
102
|
+
ip: getClientIp(req, null),
|
|
94
103
|
user_agent: req.get && req.get('user-agent') ? req.get('user-agent').slice(0, 2000) : null,
|
|
95
|
-
metadata:
|
|
104
|
+
metadata: metadataVal,
|
|
96
105
|
};
|
|
97
106
|
|
|
98
107
|
knex(tableName).insert(row).catch(logAuditError);
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
* @module plugins/audit-log/parse
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
const { escapeRegExp } = require('../../core/utils/regex');
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* Escape string for use in RegExp
|
|
8
10
|
* @param {string} s
|
|
9
11
|
* @returns {string}
|
|
10
12
|
*/
|
|
11
|
-
|
|
12
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
13
|
-
}
|
|
13
|
+
const escapeRegex = escapeRegExp;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Parse mutation target from request path relative to admin base (no trailing slash).
|
|
@@ -4,32 +4,7 @@
|
|
|
4
4
|
* @module plugins/basic-auth
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Compare two strings in constant time to prevent timing attacks.
|
|
11
|
-
* Uses dummy buffer comparison if lengths differ to avoid leaking length via response timing.
|
|
12
|
-
*
|
|
13
|
-
* @param {string} a
|
|
14
|
-
* @param {string} b
|
|
15
|
-
* @returns {boolean}
|
|
16
|
-
*/
|
|
17
|
-
function safeCompare(a, b) {
|
|
18
|
-
if (typeof a !== 'string' || typeof b !== 'string') {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const bufA = Buffer.from(a, 'utf8');
|
|
23
|
-
const bufB = Buffer.from(b, 'utf8');
|
|
24
|
-
|
|
25
|
-
if (bufA.length !== bufB.length) {
|
|
26
|
-
// Perform dummy timing-safe comparison with itself to preserve constant execution time
|
|
27
|
-
crypto.timingSafeEqual(bufA, bufA);
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return crypto.timingSafeEqual(bufA, bufB);
|
|
32
|
-
}
|
|
7
|
+
const { safeCompare } = require('../../core/utils/crypto');
|
|
33
8
|
|
|
34
9
|
/**
|
|
35
10
|
* Parse an HTTP Authorization header for Basic credentials.
|
|
@@ -69,6 +44,7 @@ function parseBasicAuthHeader(header) {
|
|
|
69
44
|
* @returns {{ username: string, password: string } | null}
|
|
70
45
|
*/
|
|
71
46
|
function extractCredentials(req) {
|
|
47
|
+
if (!req || !req.headers) return null;
|
|
72
48
|
const header = req.headers.authorization || req.headers.Authorization;
|
|
73
49
|
return parseBasicAuthHeader(header);
|
|
74
50
|
}
|
package/plugins/cors.js
CHANGED
|
@@ -105,7 +105,7 @@ function createCorsMiddleware(options = {}) {
|
|
|
105
105
|
return next();
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
const reqOrigin = req.headers
|
|
108
|
+
const reqOrigin = req.headers?.origin;
|
|
109
109
|
|
|
110
110
|
isOriginAllowed(reqOrigin, (err, allowedOrigin) => {
|
|
111
111
|
if (err) {
|
|
@@ -134,7 +134,7 @@ function createCorsMiddleware(options = {}) {
|
|
|
134
134
|
}
|
|
135
135
|
if (allowedHeadersStr) {
|
|
136
136
|
res.setHeader('Access-Control-Allow-Headers', allowedHeadersStr);
|
|
137
|
-
} else if (req.headers['access-control-request-headers']) {
|
|
137
|
+
} else if (req.headers?.['access-control-request-headers']) {
|
|
138
138
|
res.setHeader('Access-Control-Allow-Headers', req.headers['access-control-request-headers']);
|
|
139
139
|
}
|
|
140
140
|
if (config.maxAge) {
|
package/plugins/csrf/index.js
CHANGED
|
@@ -15,21 +15,8 @@ const NOOP = () => {};
|
|
|
15
15
|
const EMPTY_OBJECT = Object.freeze({});
|
|
16
16
|
const ignoreRegexCache = new Map();
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @param {string} a
|
|
21
|
-
* @param {string} b
|
|
22
|
-
* @returns {boolean}
|
|
23
|
-
*/
|
|
24
|
-
function safeCompare(a, b) {
|
|
25
|
-
if (typeof a !== 'string' || typeof b !== 'string') return false;
|
|
26
|
-
if (a.length !== b.length) return false;
|
|
27
|
-
try {
|
|
28
|
-
return crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
29
|
-
} catch (err) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
18
|
+
const { safeCompare, randomToken } = require('../../core/utils/crypto');
|
|
19
|
+
const { globToRegExp } = require('../../core/utils/regex');
|
|
33
20
|
|
|
34
21
|
/**
|
|
35
22
|
* Check if the request path matches any ignore patterns
|
|
@@ -49,12 +36,7 @@ function isIgnored(req, ignorePaths) {
|
|
|
49
36
|
if (pattern.includes('*')) {
|
|
50
37
|
let regex = ignoreRegexCache.get(pattern);
|
|
51
38
|
if (regex === undefined) {
|
|
52
|
-
|
|
53
|
-
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
54
|
-
.replace(/\*\*/g, '___GLOB_STAR_STAR___')
|
|
55
|
-
.replace(/\*/g, '[^/]*')
|
|
56
|
-
.replace(/___GLOB_STAR_STAR___/g, '.*');
|
|
57
|
-
regex = new RegExp(`^${regexPattern}$`);
|
|
39
|
+
regex = globToRegExp(pattern, { separator: '/' });
|
|
58
40
|
if (ignoreRegexCache.size < 500) {
|
|
59
41
|
ignoreRegexCache.set(pattern, regex);
|
|
60
42
|
}
|
|
@@ -163,7 +145,7 @@ function csrfPlugin(options = {}) {
|
|
|
163
145
|
if (useCookie) {
|
|
164
146
|
csrfTokenValue = cookieOptions.signed ? req.signedCookies[cookieKey] : req.cookies[cookieKey];
|
|
165
147
|
if (!csrfTokenValue) {
|
|
166
|
-
csrfTokenValue =
|
|
148
|
+
csrfTokenValue = randomToken(32, 'hex');
|
|
167
149
|
const isHttps = req.secure || req.headers?.['x-forwarded-proto'] === 'https' || process.env.NODE_ENV === 'production' || process.env.COOKIE_SECURE === 'true';
|
|
168
150
|
const effectiveCookieOptions = {
|
|
169
151
|
httpOnly: true,
|
|
@@ -176,7 +158,7 @@ function csrfPlugin(options = {}) {
|
|
|
176
158
|
} else {
|
|
177
159
|
// Session based
|
|
178
160
|
if (!req.session[sessionKey]) {
|
|
179
|
-
req.session[sessionKey] =
|
|
161
|
+
req.session[sessionKey] = randomToken(32, 'hex');
|
|
180
162
|
}
|
|
181
163
|
csrfTokenValue = req.session[sessionKey];
|
|
182
164
|
}
|
|
@@ -241,3 +223,5 @@ function csrfPlugin(options = {}) {
|
|
|
241
223
|
|
|
242
224
|
module.exports = csrfPlugin;
|
|
243
225
|
module.exports.csrfPlugin = csrfPlugin;
|
|
226
|
+
module.exports.safeCompare = safeCompare;
|
|
227
|
+
csrfPlugin.safeCompare = safeCompare;
|
package/plugins/dashboard/app.js
CHANGED
|
@@ -363,11 +363,11 @@ const ConfigView = {
|
|
|
363
363
|
m('.table-container', [
|
|
364
364
|
m('.config-item', [
|
|
365
365
|
m('.config-key', 'Port'),
|
|
366
|
-
m('.config-value', config.server?.port || '
|
|
366
|
+
m('.config-value', config.server?.port || '7331')
|
|
367
367
|
]),
|
|
368
368
|
m('.config-item', [
|
|
369
369
|
m('.config-key', 'Base URL'),
|
|
370
|
-
m('.config-value', config.server?.baseUrl || 'http://localhost:
|
|
370
|
+
m('.config-value', config.server?.baseUrl || 'http://localhost:7331')
|
|
371
371
|
])
|
|
372
372
|
])
|
|
373
373
|
])
|
|
@@ -164,16 +164,16 @@ function dashboardPlugin(options = {}) {
|
|
|
164
164
|
const config = {
|
|
165
165
|
env: filterSensitiveEnv({
|
|
166
166
|
NODE_ENV: process.env.NODE_ENV || 'development',
|
|
167
|
-
PORT: process.env.PORT || '
|
|
168
|
-
BASE_URL: process.env.BASE_URL || 'http://localhost:
|
|
167
|
+
PORT: process.env.PORT || '7331',
|
|
168
|
+
BASE_URL: process.env.BASE_URL || 'http://localhost:7331',
|
|
169
169
|
}),
|
|
170
170
|
i18n: {
|
|
171
171
|
defaultLocale: process.env.DEFAULT_LOCALE || 'en',
|
|
172
172
|
supportedLocales: (process.env.SUPPORTED_LOCALES || 'en').split(','),
|
|
173
173
|
},
|
|
174
174
|
server: {
|
|
175
|
-
port: process.env.PORT || '
|
|
176
|
-
baseUrl: process.env.BASE_URL || 'http://localhost:
|
|
175
|
+
port: process.env.PORT || '7331',
|
|
176
|
+
baseUrl: process.env.BASE_URL || 'http://localhost:7331',
|
|
177
177
|
},
|
|
178
178
|
database: {
|
|
179
179
|
connected: hasDb(),
|
|
@@ -232,7 +232,7 @@ function dashboardPlugin(options = {}) {
|
|
|
232
232
|
});
|
|
233
233
|
|
|
234
234
|
// Log dashboard URL
|
|
235
|
-
console.log(`\n📊 Dashboard available at: http://localhost:${process.env.PORT ||
|
|
235
|
+
console.log(`\n📊 Dashboard available at: http://localhost:${process.env.PORT || 7331}${dashboardPath}\n`);
|
|
236
236
|
},
|
|
237
237
|
};
|
|
238
238
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const { buildFilteredQuery } = require('../admin-panel/core/api-extensions');
|
|
7
|
+
const { safeJsonParse } = require('../../core/utils/json');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @param {import('../../core/orm/database').Database} db
|
|
@@ -17,11 +18,7 @@ async function resolveExportRecords(db, modelName, req) {
|
|
|
17
18
|
let filters = body.filters ?? req.query.filters;
|
|
18
19
|
if (typeof selectAll === 'string') selectAll = selectAll === 'true';
|
|
19
20
|
if (typeof filters === 'string') {
|
|
20
|
-
|
|
21
|
-
filters = JSON.parse(filters);
|
|
22
|
-
} catch {
|
|
23
|
-
filters = undefined;
|
|
24
|
-
}
|
|
21
|
+
filters = safeJsonParse(filters, undefined);
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
const trashedOnly =
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const { purgeEmailLogs } = require('./purge');
|
|
7
|
+
const { safeJsonParse } = require('../../core/utils/json');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @param {Object} options
|
|
@@ -44,14 +45,7 @@ function createEmailApiHandlers(options) {
|
|
|
44
45
|
return res.status(400).json({ error: 'to and subject are required' });
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
if (typeof data === 'string') {
|
|
49
|
-
try {
|
|
50
|
-
parsedData = JSON.parse(data);
|
|
51
|
-
} catch {
|
|
52
|
-
parsedData = {};
|
|
53
|
-
}
|
|
54
|
-
}
|
|
48
|
+
const parsedData = safeJsonParse(data, {}) || {};
|
|
55
49
|
|
|
56
50
|
const result = await emailService.send({
|
|
57
51
|
to,
|
|
@@ -59,7 +53,7 @@ function createEmailApiHandlers(options) {
|
|
|
59
53
|
template,
|
|
60
54
|
mjml,
|
|
61
55
|
html,
|
|
62
|
-
data: parsedData
|
|
56
|
+
data: parsedData,
|
|
63
57
|
});
|
|
64
58
|
|
|
65
59
|
res.json({ ok: true, ...result });
|
|
@@ -73,17 +67,10 @@ function createEmailApiHandlers(options) {
|
|
|
73
67
|
const body = req.body || {};
|
|
74
68
|
const { template, mjml, html, data } = body;
|
|
75
69
|
|
|
76
|
-
|
|
77
|
-
if (typeof data === 'string') {
|
|
78
|
-
try {
|
|
79
|
-
parsedData = JSON.parse(data);
|
|
80
|
-
} catch {
|
|
81
|
-
parsedData = {};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
70
|
+
const parsedData = safeJsonParse(data, {}) || {};
|
|
84
71
|
|
|
85
72
|
const result = await emailService.preview(
|
|
86
|
-
template ? { template, data: parsedData
|
|
73
|
+
template ? { template, data: parsedData } : { mjml, html, data: parsedData }
|
|
87
74
|
);
|
|
88
75
|
|
|
89
76
|
res.json(result);
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
const { createKnexAuthTokensAdapter } = require('../../core/auth/tokens');
|
|
7
7
|
const { registerBundledAuthTemplates } = require('./bundled-templates');
|
|
8
|
+
const { stripTrailingSlash } = require('../../core/utils/url');
|
|
8
9
|
|
|
9
10
|
const DEFAULT_AUTH_EMAILS = {
|
|
10
11
|
passwordReset: {
|
|
@@ -62,7 +63,7 @@ function wireAuthEmails(authManager, emailService, registry, config, db) {
|
|
|
62
63
|
authManager.authTokens = createKnexAuthTokensAdapter(db);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
const baseUrl = (merged.baseUrl || process.env.BASE_URL || 'http://localhost:
|
|
66
|
+
const baseUrl = stripTrailingSlash(merged.baseUrl || process.env.BASE_URL || 'http://localhost:7331');
|
|
66
67
|
const identifierField = authManager.identifierField || 'email';
|
|
67
68
|
|
|
68
69
|
function userDisplayName(user) {
|
|
@@ -153,7 +154,7 @@ function registerAuthEmailRoutes(options) {
|
|
|
153
154
|
const guest = ctx.middlewares?.guest;
|
|
154
155
|
const authMw = ctx.middlewares?.auth;
|
|
155
156
|
|
|
156
|
-
const base = (authEmailsConfig.baseUrl || process.env.BASE_URL || 'http://localhost:
|
|
157
|
+
const base = stripTrailingSlash(authEmailsConfig.baseUrl || process.env.BASE_URL || 'http://localhost:7331');
|
|
157
158
|
|
|
158
159
|
async function forgotPasswordHandler(req, res) {
|
|
159
160
|
try {
|
|
@@ -173,10 +173,12 @@ function generateFileManagerComponent(options = {}) {
|
|
|
173
173
|
|
|
174
174
|
var uploadUrl = (window.__ADMIN_PATH__ || '/_admin') + '/api' + API + '/upload?path=' + encodeURIComponent(currentPath);
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
var fetchFn = (typeof window !== 'undefined' && window.Admin && window.Admin.fetch) ? window.Admin.fetch : fetch;
|
|
177
|
+
fetchFn(uploadUrl, {
|
|
177
178
|
method: 'POST',
|
|
178
179
|
body: fd,
|
|
179
180
|
credentials: 'include',
|
|
181
|
+
timeout: 60000,
|
|
180
182
|
}).then(function(r) { return r.json(); }).then(function(res) {
|
|
181
183
|
uploading = false;
|
|
182
184
|
uploadStatus = '';
|
|
@@ -137,7 +137,12 @@ function resolveSafePath(baseDir, relPath = '') {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
// Prevent URL decoded traversal attempts
|
|
140
|
-
|
|
140
|
+
let decodedPath;
|
|
141
|
+
try {
|
|
142
|
+
decodedPath = decodeURIComponent(relPath);
|
|
143
|
+
} catch (err) {
|
|
144
|
+
throw new ValidationError('Malformed URI path sequence', 400);
|
|
145
|
+
}
|
|
141
146
|
if (decodedPath.includes('\0')) {
|
|
142
147
|
throw new SecurityError('Null byte detected in path', 400);
|
|
143
148
|
}
|
|
@@ -237,7 +242,7 @@ function buildBreadcrumbs(relPath) {
|
|
|
237
242
|
*/
|
|
238
243
|
async function listFiles(baseDir, relPath = '', options = {}) {
|
|
239
244
|
const targetDir = resolveSafePath(baseDir, relPath);
|
|
240
|
-
const normalizedRel = path.relative(path.resolve(baseDir), targetDir).replace(/\\/g, '');
|
|
245
|
+
const normalizedRel = path.relative(path.resolve(baseDir), targetDir).replace(/\\/g, '/');
|
|
241
246
|
const publicBase = normalizePublicBase(options.publicBasePath);
|
|
242
247
|
|
|
243
248
|
let dirents;
|
|
@@ -456,6 +461,7 @@ async function deleteItem(baseDir, itemRelPath) {
|
|
|
456
461
|
await fs.unlink(targetFullPath);
|
|
457
462
|
}
|
|
458
463
|
|
|
464
|
+
invalidateStorageCache(baseDir);
|
|
459
465
|
return { success: true, path: itemRelPath };
|
|
460
466
|
}
|
|
461
467
|
|
|
@@ -487,12 +493,33 @@ async function moveItem(baseDir, sourceRelPath, destDirRelPath) {
|
|
|
487
493
|
return { success: true, oldPath: sourceRelPath, newPath: newRelPath };
|
|
488
494
|
}
|
|
489
495
|
|
|
496
|
+
const storageCache = new Map();
|
|
497
|
+
const STORAGE_CACHE_TTL = 15000; // 15 seconds
|
|
498
|
+
|
|
499
|
+
function invalidateStorageCache(baseDir) {
|
|
500
|
+
if (baseDir) {
|
|
501
|
+
storageCache.delete(path.resolve(baseDir));
|
|
502
|
+
} else {
|
|
503
|
+
storageCache.clear();
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
490
507
|
/**
|
|
491
508
|
* Calculate total disk usage in bytes under baseDir
|
|
492
509
|
* @param {string} baseDir
|
|
510
|
+
* @param {Object} [options]
|
|
511
|
+
* @param {boolean} [options.forceRefresh=false]
|
|
493
512
|
* @returns {Promise<number>}
|
|
494
513
|
*/
|
|
495
|
-
async function calculateStorageUsage(baseDir) {
|
|
514
|
+
async function calculateStorageUsage(baseDir, options = {}) {
|
|
515
|
+
const resolvedBase = path.resolve(baseDir);
|
|
516
|
+
const now = Date.now();
|
|
517
|
+
const cached = storageCache.get(resolvedBase);
|
|
518
|
+
|
|
519
|
+
if (!options.forceRefresh && cached && (now - cached.timestamp) < STORAGE_CACHE_TTL) {
|
|
520
|
+
return cached.bytes;
|
|
521
|
+
}
|
|
522
|
+
|
|
496
523
|
let totalBytes = 0;
|
|
497
524
|
async function scan(dir) {
|
|
498
525
|
try {
|
|
@@ -509,7 +536,8 @@ async function calculateStorageUsage(baseDir) {
|
|
|
509
536
|
}
|
|
510
537
|
} catch (e) {}
|
|
511
538
|
}
|
|
512
|
-
await scan(
|
|
539
|
+
await scan(resolvedBase);
|
|
540
|
+
storageCache.set(resolvedBase, { bytes: totalBytes, timestamp: now });
|
|
513
541
|
return totalBytes;
|
|
514
542
|
}
|
|
515
543
|
|
|
@@ -568,6 +596,7 @@ async function saveUploadedFile(baseDir, targetDirRelPath, buffer, originalName,
|
|
|
568
596
|
resolveSafePath(baseDir, path.relative(baseDir, targetPath));
|
|
569
597
|
|
|
570
598
|
await fs.writeFile(targetPath, finalBuffer);
|
|
599
|
+
invalidateStorageCache(baseDir);
|
|
571
600
|
|
|
572
601
|
const relFilePath = path.relative(path.resolve(baseDir), targetPath).replace(/\\/g, '/');
|
|
573
602
|
const publicBase = normalizePublicBase(publicBasePath);
|
|
@@ -598,4 +627,5 @@ module.exports = {
|
|
|
598
627
|
moveItem,
|
|
599
628
|
saveUploadedFile,
|
|
600
629
|
calculateStorageUsage,
|
|
630
|
+
invalidateStorageCache,
|
|
601
631
|
};
|
package/plugins/health-check.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
const pathMod = require('path');
|
|
6
6
|
const PKG = require(pathMod.join(__dirname, '..', 'package.json'));
|
|
7
|
+
const { ensureLeadingSlash } = require('../core/utils/url');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @param {Object} [options]
|
|
@@ -23,7 +24,7 @@ function healthCheckPlugin(options = {}) {
|
|
|
23
24
|
} = options;
|
|
24
25
|
|
|
25
26
|
const isEnabled = enabled !== undefined ? enabled : true;
|
|
26
|
-
const normalizedPath = routePath
|
|
27
|
+
const normalizedPath = ensureLeadingSlash(routePath);
|
|
27
28
|
|
|
28
29
|
return {
|
|
29
30
|
name: 'health-check',
|
package/plugins/index.js
CHANGED
|
@@ -63,6 +63,8 @@ module.exports = {
|
|
|
63
63
|
get WebhookDispatcher() { return require('./webhooks').WebhookDispatcher; },
|
|
64
64
|
get lazyPlugin() { return require('./lazy').lazyPlugin; },
|
|
65
65
|
get defineLazyPlugin() { return require('./lazy').defineLazyPlugin; },
|
|
66
|
+
get rlsPlugin() { return require('./rls').rlsPlugin; },
|
|
67
|
+
get createRlsMiddleware() { return require('./rls').createRlsMiddleware; },
|
|
66
68
|
};
|
|
67
69
|
|
|
68
70
|
|
package/plugins/lazy.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
const express = require('express');
|
|
16
|
+
const { ensureArray } = require('../core/utils/object');
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Wraps a plugin definition or factory function into an on-demand lazy plugin.
|
|
@@ -43,9 +44,7 @@ function lazyPlugin(pluginFactory, lazyOptions = {}) {
|
|
|
43
44
|
(typeof pluginFactory === 'object' && pluginFactory ? pluginFactory.name : null) ||
|
|
44
45
|
'anonymous-lazy-plugin';
|
|
45
46
|
|
|
46
|
-
const rawPrefixes = lazyOptions.prefix
|
|
47
|
-
? (Array.isArray(lazyOptions.prefix) ? lazyOptions.prefix : [lazyOptions.prefix])
|
|
48
|
-
: [];
|
|
47
|
+
const rawPrefixes = ensureArray(lazyOptions.prefix);
|
|
49
48
|
// Normalize prefixes: ensure leading slash, remove trailing slash (except root '/')
|
|
50
49
|
const prefixes = rawPrefixes.map(p => {
|
|
51
50
|
let norm = String(p).trim();
|
|
@@ -54,9 +53,9 @@ function lazyPlugin(pluginFactory, lazyOptions = {}) {
|
|
|
54
53
|
return norm;
|
|
55
54
|
});
|
|
56
55
|
|
|
57
|
-
const lazyServices =
|
|
58
|
-
const lazyHelpers =
|
|
59
|
-
const lazyEvents =
|
|
56
|
+
const lazyServices = ensureArray(lazyOptions.services);
|
|
57
|
+
const lazyHelpers = ensureArray(lazyOptions.helpers);
|
|
58
|
+
const lazyEvents = ensureArray(lazyOptions.events);
|
|
60
59
|
|
|
61
60
|
function hydrate() {
|
|
62
61
|
if (isHydrated) return realPlugin;
|
package/plugins/mcp/auth.js
CHANGED
|
@@ -6,19 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
const crypto = require('crypto');
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
* Constant-time string comparison to avoid timing attacks
|
|
11
|
-
* @param {string} a
|
|
12
|
-
* @param {string} b
|
|
13
|
-
* @returns {boolean}
|
|
14
|
-
*/
|
|
15
|
-
function safeEqual(a, b) {
|
|
16
|
-
if (typeof a !== 'string' || typeof b !== 'string') return false;
|
|
17
|
-
const bufA = Buffer.from(a);
|
|
18
|
-
const bufB = Buffer.from(b);
|
|
19
|
-
if (bufA.length !== bufB.length) return false;
|
|
20
|
-
return crypto.timingSafeEqual(bufA, bufB);
|
|
21
|
-
}
|
|
9
|
+
const { safeCompare: safeEqual } = require('../../core/utils/crypto');
|
|
22
10
|
|
|
23
11
|
/**
|
|
24
12
|
* Check if incoming request is from localhost
|
package/plugins/mcp/discovery.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
const fs = require('fs');
|
|
8
8
|
const path = require('path');
|
|
9
|
+
const { walkDirectory } = require('../../core/utils/fs');
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Scan a directory for JS files and require them
|
|
@@ -13,27 +14,27 @@ const path = require('path');
|
|
|
13
14
|
* @returns {Array<Object>}
|
|
14
15
|
*/
|
|
15
16
|
function scanModuleDir(dirPath) {
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const files = walkDirectory(dirPath, {
|
|
18
|
+
recursive: false,
|
|
19
|
+
extensions: ['.js', '.cjs'],
|
|
20
|
+
ignorePrefixes: ['_', '.'],
|
|
21
|
+
ignoreTests: true,
|
|
22
|
+
});
|
|
18
23
|
const items = [];
|
|
19
24
|
|
|
20
|
-
for (const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!mod.name && !mod.uri) {
|
|
29
|
-
const baseName = path.basename(entry.name, path.extname(entry.name));
|
|
30
|
-
mod.name = baseName;
|
|
31
|
-
}
|
|
32
|
-
items.push(mod);
|
|
25
|
+
for (const fullPath of files) {
|
|
26
|
+
try {
|
|
27
|
+
const mod = require(fullPath);
|
|
28
|
+
if (mod && typeof mod === 'object') {
|
|
29
|
+
// If mod doesn't have a name, default to filename without extension
|
|
30
|
+
if (!mod.name && !mod.uri) {
|
|
31
|
+
const baseName = path.basename(fullPath, path.extname(fullPath));
|
|
32
|
+
mod.name = baseName;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
console.warn(`[mcp-discovery] Failed to load module at ${fullPath}:`, err.message);
|
|
34
|
+
items.push(mod);
|
|
36
35
|
}
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.warn(`[mcp-discovery] Failed to load module at ${fullPath}:`, err.message);
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|