devanvil 2.1.0 → 2.1.1
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/SECURITY.md +4 -4
- package/dist/cli.js +6 -1
- package/dist/core/contract-drift.js +15 -5
- package/dist/core/converters.js +25 -17
- package/dist/core/cron.js +6 -3
- package/dist/core/crypto.js +11 -1
- package/dist/core/curl.js +5 -1
- package/dist/core/diff.js +2 -2
- package/dist/core/encoding.js +1 -1
- package/dist/core/jwt.js +21 -8
- package/dist/core/oauth-protobuf.js +16 -10
- package/dist/core/regex.js +13 -4
- package/dist/core/secrets.js +11 -7
- package/dist/core/security.js +20 -3
- package/dist/core/tls.js +5 -2
- package/dist/server/app.d.ts +1 -1
- package/dist/server/app.js +17 -6
- package/dist/server/http-proxy.js +19 -10
- package/dist/server/http-utils.js +15 -3
- package/dist/server/load-tester.js +3 -0
- package/dist/server/mcp.d.ts +1 -1
- package/dist/server/mcp.js +8 -4
- package/dist/server/mock-store.js +54 -13
- package/dist/server/plugin-loader.d.ts +2 -1
- package/dist/server/plugin-loader.js +21 -1
- package/dist/server/recorder-store.js +2 -1
- package/dist/server/routes/network-routes.js +54 -4
- package/dist/server/routes/tools-routes.js +9 -2
- package/dist/server/routes/workspace-routes.js +26 -4
- package/dist/server/webhook-store.js +12 -2
- package/dist/server/workspace-store.js +4 -3
- package/dist/server/ws-probe.js +8 -0
- package/dist/ui/app.js +20 -4
- package/dist/ui/styles.css +2 -2
- package/dist/ui/tools-data.js +42 -27
- package/dist/ui/tools-network.js +70 -28
- package/dist/ui/tools-ops.js +16 -12
- package/dist/ui/tools-security.js +30 -22
- package/dist/ui/tools-v12.js +34 -14
- package/dist/ui/tools-v21.js +26 -10
- package/package.json +1 -1
package/SECURITY.md
CHANGED
|
@@ -4,10 +4,10 @@ DevAnvil is designed from day one for developers handling sensitive payloads (JW
|
|
|
4
4
|
|
|
5
5
|
## Supported Versions
|
|
6
6
|
|
|
7
|
-
| Version
|
|
8
|
-
|
|
|
9
|
-
| 1.1
|
|
10
|
-
| 1.0
|
|
7
|
+
| Version | Supported |
|
|
8
|
+
| --------- | --------- |
|
|
9
|
+
| `>= 2.1.1` | Yes (current hardened release) |
|
|
10
|
+
| `<= 2.1.0` | Deprecated — please upgrade to `v2.1.1+` for SSRF, CSP, sandbox & parser security fixes |
|
|
11
11
|
|
|
12
12
|
## Threat Model & Built-in Defenses
|
|
13
13
|
|
package/dist/cli.js
CHANGED
|
@@ -279,8 +279,10 @@ async function main() {
|
|
|
279
279
|
...(hasThresholds ? { thresholds: { maxP95Ms, minRps, maxErrorRatePct } } : {}),
|
|
280
280
|
}, { allowPrivate: Boolean(flags['allow-private'] || flags['allow-private-proxy']) });
|
|
281
281
|
console.log(JSON.stringify(report, null, 2));
|
|
282
|
-
|
|
282
|
+
// If --max-error-rate threshold is explicitly provided, honor thresholdsPassed; otherwise fail on any failed request
|
|
283
|
+
if (!report.thresholdsPassed || (maxErrorRatePct === undefined && report.failedRequests > 0)) {
|
|
283
284
|
process.exitCode = 1;
|
|
285
|
+
}
|
|
284
286
|
return;
|
|
285
287
|
}
|
|
286
288
|
if (cmd === 'drift') {
|
|
@@ -381,6 +383,9 @@ async function main() {
|
|
|
381
383
|
const parsed = parseOpenApiSpec(raw);
|
|
382
384
|
if (flags.serve) {
|
|
383
385
|
const port = Number(flags.port ?? flags.p ?? 4321);
|
|
386
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
387
|
+
throw new Error(`Invalid port: ${port}`);
|
|
388
|
+
}
|
|
384
389
|
const host = String(flags.host ?? flags.H ?? '127.0.0.1');
|
|
385
390
|
const app = createDevAnvilServer({ host, port });
|
|
386
391
|
const routes = openApiToMockRoutes(parsed);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isIP } from 'node:net';
|
|
1
2
|
import { parseYaml } from './converters.js';
|
|
2
3
|
import { parseOpenApiSpec } from './openapi.js';
|
|
3
4
|
import { safeJsonParse } from './security.js';
|
|
@@ -53,7 +54,9 @@ function isValidFormat(format, value) {
|
|
|
53
54
|
case 'url':
|
|
54
55
|
return /^https?:\/\/\S+$/i.test(value);
|
|
55
56
|
case 'ipv4':
|
|
56
|
-
return
|
|
57
|
+
return isIP(value) === 4;
|
|
58
|
+
case 'ipv6':
|
|
59
|
+
return isIP(value) === 6;
|
|
57
60
|
default:
|
|
58
61
|
return true;
|
|
59
62
|
}
|
|
@@ -63,7 +66,7 @@ function resolveRefSchema(schema, components, depth = 0) {
|
|
|
63
66
|
return schema;
|
|
64
67
|
if (typeof schema.$ref === 'string') {
|
|
65
68
|
const refName = schema.$ref.split('/').pop() ?? '';
|
|
66
|
-
const target = components[refName];
|
|
69
|
+
const target = Object.prototype.hasOwnProperty.call(components, refName) ? components[refName] : undefined;
|
|
67
70
|
if (target)
|
|
68
71
|
return resolveRefSchema(target, components, depth + 1);
|
|
69
72
|
}
|
|
@@ -94,7 +97,14 @@ function extractRawResponseSchema(rawSpec, endpoint, status) {
|
|
|
94
97
|
const op = pathItem[endpoint.method.toLowerCase()] ?? {};
|
|
95
98
|
const responses = op.responses ?? {};
|
|
96
99
|
const statusKey = String(status);
|
|
97
|
-
const
|
|
100
|
+
const wildcardKey = `${Math.floor(status / 100)}XX`;
|
|
101
|
+
const statusObj = Object.prototype.hasOwnProperty.call(responses, statusKey)
|
|
102
|
+
? responses[statusKey]
|
|
103
|
+
: Object.prototype.hasOwnProperty.call(responses, wildcardKey)
|
|
104
|
+
? responses[wildcardKey]
|
|
105
|
+
: Object.prototype.hasOwnProperty.call(responses, 'default')
|
|
106
|
+
? responses.default
|
|
107
|
+
: undefined;
|
|
98
108
|
if (!statusObj) {
|
|
99
109
|
return { hasStatusDoc: false, components: schemasMap };
|
|
100
110
|
}
|
|
@@ -171,7 +181,7 @@ function validateValueAgainstSchema(value, rawSchema, components, jsonPath, issu
|
|
|
171
181
|
const obj = value;
|
|
172
182
|
const requiredFields = Array.isArray(schema.required) ? schema.required : [];
|
|
173
183
|
for (const reqKey of requiredFields) {
|
|
174
|
-
if (!(reqKey
|
|
184
|
+
if (!Object.prototype.hasOwnProperty.call(obj, reqKey)) {
|
|
175
185
|
issues.push({
|
|
176
186
|
severity: 'breaking',
|
|
177
187
|
code: 'MISSING_REQUIRED_FIELD',
|
|
@@ -184,7 +194,7 @@ function validateValueAgainstSchema(value, rawSchema, components, jsonPath, issu
|
|
|
184
194
|
}
|
|
185
195
|
const props = schema.properties ?? {};
|
|
186
196
|
for (const [k, v] of Object.entries(obj)) {
|
|
187
|
-
const propSchema = props[k];
|
|
197
|
+
const propSchema = Object.prototype.hasOwnProperty.call(props, k) ? props[k] : undefined;
|
|
188
198
|
if (!propSchema) {
|
|
189
199
|
if (Object.keys(props).length > 0) {
|
|
190
200
|
issues.push({
|
package/dist/core/converters.js
CHANGED
|
@@ -146,20 +146,24 @@ export function parseYaml(input) {
|
|
|
146
146
|
if (lines.length === 0)
|
|
147
147
|
return {};
|
|
148
148
|
let idx = 0;
|
|
149
|
-
function parseBlock(minIndent) {
|
|
149
|
+
function parseBlock(minIndent, depth = 0) {
|
|
150
|
+
if (depth > 64)
|
|
151
|
+
throw new Error('YAML nesting depth limit exceeded (max 64)');
|
|
150
152
|
if (idx >= lines.length)
|
|
151
153
|
return null;
|
|
152
154
|
const first = lines[idx];
|
|
153
155
|
if (first.text.startsWith('- ') || first.text === '-') {
|
|
154
|
-
return parseSequence(first.indent);
|
|
156
|
+
return parseSequence(first.indent, depth + 1);
|
|
155
157
|
}
|
|
156
158
|
if (findUnquotedChar(first.text, ':') !== -1) {
|
|
157
|
-
return parseMapping(first.indent);
|
|
159
|
+
return parseMapping(first.indent, depth + 1);
|
|
158
160
|
}
|
|
159
161
|
idx++;
|
|
160
162
|
return parseYamlScalar(first.text);
|
|
161
163
|
}
|
|
162
|
-
function parseSequence(seqIndent) {
|
|
164
|
+
function parseSequence(seqIndent, depth = 0) {
|
|
165
|
+
if (depth > 64)
|
|
166
|
+
throw new Error('YAML nesting depth limit exceeded (max 64)');
|
|
163
167
|
const arr = [];
|
|
164
168
|
while (idx < lines.length) {
|
|
165
169
|
const line = lines[idx];
|
|
@@ -171,7 +175,7 @@ export function parseYaml(input) {
|
|
|
171
175
|
idx++;
|
|
172
176
|
if (!rest) {
|
|
173
177
|
if (idx < lines.length && lines[idx].indent > seqIndent) {
|
|
174
|
-
arr.push(parseBlock(lines[idx].indent));
|
|
178
|
+
arr.push(parseBlock(lines[idx].indent, depth + 1));
|
|
175
179
|
}
|
|
176
180
|
else {
|
|
177
181
|
arr.push(null);
|
|
@@ -190,7 +194,7 @@ export function parseYaml(input) {
|
|
|
190
194
|
firstVal = parseYamlScalar(vRaw);
|
|
191
195
|
}
|
|
192
196
|
else if (idx < lines.length && lines[idx].indent > itemIndent) {
|
|
193
|
-
firstVal = parseBlock(lines[idx].indent);
|
|
197
|
+
firstVal = parseBlock(lines[idx].indent, depth + 1);
|
|
194
198
|
}
|
|
195
199
|
else {
|
|
196
200
|
firstVal = null;
|
|
@@ -216,7 +220,7 @@ export function parseYaml(input) {
|
|
|
216
220
|
parsedSubVal = parseYamlScalar(subVal);
|
|
217
221
|
}
|
|
218
222
|
else if (idx < lines.length && lines[idx].indent > sub.indent) {
|
|
219
|
-
parsedSubVal = parseBlock(lines[idx].indent);
|
|
223
|
+
parsedSubVal = parseBlock(lines[idx].indent, depth + 1);
|
|
220
224
|
}
|
|
221
225
|
else {
|
|
222
226
|
parsedSubVal = null;
|
|
@@ -241,7 +245,9 @@ export function parseYaml(input) {
|
|
|
241
245
|
}
|
|
242
246
|
return chunks.join(folded ? ' ' : '\n');
|
|
243
247
|
}
|
|
244
|
-
function parseMapping(mapIndent) {
|
|
248
|
+
function parseMapping(mapIndent, depth = 0) {
|
|
249
|
+
if (depth > 64)
|
|
250
|
+
throw new Error('YAML nesting depth limit exceeded (max 64)');
|
|
245
251
|
const obj = Object.create(null);
|
|
246
252
|
while (idx < lines.length) {
|
|
247
253
|
const line = lines[idx];
|
|
@@ -266,10 +272,10 @@ export function parseYaml(input) {
|
|
|
266
272
|
parsedVal = parseYamlScalar(valRaw);
|
|
267
273
|
}
|
|
268
274
|
else if (idx < lines.length && lines[idx].indent > mapIndent) {
|
|
269
|
-
parsedVal = parseBlock(lines[idx].indent);
|
|
275
|
+
parsedVal = parseBlock(lines[idx].indent, depth + 1);
|
|
270
276
|
}
|
|
271
277
|
else if (idx < lines.length && lines[idx].indent === mapIndent && lines[idx].text.startsWith('-')) {
|
|
272
|
-
parsedVal = parseSequence(mapIndent);
|
|
278
|
+
parsedVal = parseSequence(mapIndent, depth + 1);
|
|
273
279
|
}
|
|
274
280
|
else {
|
|
275
281
|
parsedVal = null;
|
|
@@ -347,7 +353,9 @@ export function stringifyYaml(value, indent = 0) {
|
|
|
347
353
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
348
354
|
// TOML Parser & Serializer
|
|
349
355
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
350
|
-
function parseTomlValue(raw) {
|
|
356
|
+
function parseTomlValue(raw, depth = 0) {
|
|
357
|
+
if (depth > 32)
|
|
358
|
+
throw new Error('TOML inline nesting depth limit exceeded (max 32)');
|
|
351
359
|
const s = raw.trim();
|
|
352
360
|
if (s === 'true')
|
|
353
361
|
return true;
|
|
@@ -362,7 +370,7 @@ function parseTomlValue(raw) {
|
|
|
362
370
|
const inner = s.slice(1, -1).trim();
|
|
363
371
|
if (!inner)
|
|
364
372
|
return [];
|
|
365
|
-
return splitTopLevel(inner, ',').map((part) => parseTomlValue(part));
|
|
373
|
+
return splitTopLevel(inner, ',').map((part) => parseTomlValue(part, depth + 1));
|
|
366
374
|
}
|
|
367
375
|
if (s.startsWith('{') && s.endsWith('}')) {
|
|
368
376
|
const inner = s.slice(1, -1).trim();
|
|
@@ -374,7 +382,7 @@ function parseTomlValue(raw) {
|
|
|
374
382
|
if (eq > 0) {
|
|
375
383
|
const k = stripQuotes(pair.slice(0, eq).trim());
|
|
376
384
|
if (!isDangerousKey(k)) {
|
|
377
|
-
obj[k] = parseTomlValue(pair.slice(eq + 1));
|
|
385
|
+
obj[k] = parseTomlValue(pair.slice(eq + 1), depth + 1);
|
|
378
386
|
}
|
|
379
387
|
}
|
|
380
388
|
}
|
|
@@ -901,19 +909,19 @@ export function queryJsonPath(data, expression) {
|
|
|
901
909
|
}
|
|
902
910
|
return results;
|
|
903
911
|
}
|
|
904
|
-
function collectRecursive(node, key, acc) {
|
|
905
|
-
if (!node || typeof node !== 'object' || isDangerousKey(key))
|
|
912
|
+
function collectRecursive(node, key, acc, depth = 0) {
|
|
913
|
+
if (depth > 32 || !node || typeof node !== 'object' || isDangerousKey(key))
|
|
906
914
|
return;
|
|
907
915
|
if (Array.isArray(node)) {
|
|
908
916
|
for (const el of node)
|
|
909
|
-
collectRecursive(el, key, acc);
|
|
917
|
+
collectRecursive(el, key, acc, depth + 1);
|
|
910
918
|
return;
|
|
911
919
|
}
|
|
912
920
|
const obj = node;
|
|
913
921
|
if (Object.prototype.hasOwnProperty.call(obj, key))
|
|
914
922
|
acc.push(obj[key]);
|
|
915
923
|
for (const val of Object.values(obj)) {
|
|
916
|
-
collectRecursive(val, key, acc);
|
|
924
|
+
collectRecursive(val, key, acc, depth + 1);
|
|
917
925
|
}
|
|
918
926
|
}
|
|
919
927
|
// ─────────────────────────────────────────────────────────────────────────────
|
package/dist/core/cron.js
CHANGED
|
@@ -22,7 +22,8 @@ function parseCronField(raw, min, max, names, isDow = false) {
|
|
|
22
22
|
if (!names)
|
|
23
23
|
return tok;
|
|
24
24
|
return tok.replace(/[A-Za-z]{3}/g, (m) => {
|
|
25
|
-
const
|
|
25
|
+
const up = m.toUpperCase();
|
|
26
|
+
const val = Object.prototype.hasOwnProperty.call(names, up) ? names[up] : undefined;
|
|
26
27
|
if (val === undefined)
|
|
27
28
|
throw new Error(`Unknown cron token "${m}"`);
|
|
28
29
|
return String(val);
|
|
@@ -72,7 +73,8 @@ function parseCronField(raw, min, max, names, isDow = false) {
|
|
|
72
73
|
}
|
|
73
74
|
export function parseCron(expression) {
|
|
74
75
|
const trimmed = expression.trim();
|
|
75
|
-
const
|
|
76
|
+
const lower = trimmed.toLowerCase();
|
|
77
|
+
const expanded = Object.prototype.hasOwnProperty.call(CRON_MACROS, lower) ? CRON_MACROS[lower] : trimmed;
|
|
76
78
|
const fields = expanded.split(/\s+/);
|
|
77
79
|
if (fields.length !== 5 && fields.length !== 6) {
|
|
78
80
|
throw new Error(`Cron expression must have 5 fields (min hour dom month dow) or 6 fields (sec ...), got ${fields.length}`);
|
|
@@ -143,7 +145,8 @@ function nextAllowed(sortedValues, current) {
|
|
|
143
145
|
}
|
|
144
146
|
export function getNextCronRuns(expression, count = 10, fromDate = new Date()) {
|
|
145
147
|
const parsed = parseCron(expression);
|
|
146
|
-
const
|
|
148
|
+
const safeCount = Number.isFinite(count) ? Math.floor(count) : 10;
|
|
149
|
+
const maxCount = Math.min(Math.max(safeCount, 1), 50);
|
|
147
150
|
const runs = [];
|
|
148
151
|
const sortedHours = Array.from(parsed.hours).sort((a, b) => a - b);
|
|
149
152
|
const sortedMinutes = Array.from(parsed.minutes).sort((a, b) => a - b);
|
package/dist/core/crypto.js
CHANGED
|
@@ -88,7 +88,17 @@ export function decryptAesGcm(envelope, passphrase) {
|
|
|
88
88
|
export function deriveKey(password, options = {}) {
|
|
89
89
|
const kdf = options.kdf ?? 'scrypt';
|
|
90
90
|
const keyLength = Math.min(Math.max(options.keyLength ?? 32, 16), 64);
|
|
91
|
-
|
|
91
|
+
let salt;
|
|
92
|
+
if (options.saltHex !== undefined && options.saltHex !== '') {
|
|
93
|
+
const cleanSalt = options.saltHex.trim();
|
|
94
|
+
if (!/^[0-9a-fA-F]+$/.test(cleanSalt) || cleanSalt.length % 2 !== 0 || cleanSalt.length < 16) {
|
|
95
|
+
throw new Error('saltHex must be a valid even-length hexadecimal string of at least 8 bytes (16 hex chars)');
|
|
96
|
+
}
|
|
97
|
+
salt = Buffer.from(cleanSalt, 'hex');
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
salt = randomBytes(16);
|
|
101
|
+
}
|
|
92
102
|
let derived;
|
|
93
103
|
if (kdf === 'pbkdf2') {
|
|
94
104
|
const iterations = Math.min(Math.max(options.iterations ?? 210_000, 10_000), 1_000_000);
|
package/dist/core/curl.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isDangerousKey } from './security.js';
|
|
1
2
|
function tokenizeShellArgs(command) {
|
|
2
3
|
const tokens = [];
|
|
3
4
|
let current = '';
|
|
@@ -68,7 +69,10 @@ export function parseCurlCommand(curlCmd) {
|
|
|
68
69
|
const hdr = args[++i] ?? '';
|
|
69
70
|
const idx = hdr.indexOf(':');
|
|
70
71
|
if (idx > 0) {
|
|
71
|
-
|
|
72
|
+
const key = hdr.slice(0, idx).trim();
|
|
73
|
+
if (key && !isDangerousKey(key)) {
|
|
74
|
+
headers[key] = hdr.slice(idx + 1).trim();
|
|
75
|
+
}
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
else if (arg === '-d' || arg === '--data' || arg === '--data-raw' || arg === '--data-binary') {
|
package/dist/core/diff.js
CHANGED
|
@@ -120,10 +120,10 @@ function compareJsonValues(a, b, path, changes) {
|
|
|
120
120
|
const allKeys = Array.from(new Set([...Object.keys(objA), ...Object.keys(objB)])).sort();
|
|
121
121
|
for (const key of allKeys) {
|
|
122
122
|
const propPath = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? `${path}.${key}` : `${path}[${JSON.stringify(key)}]`;
|
|
123
|
-
if (!(key
|
|
123
|
+
if (!Object.prototype.hasOwnProperty.call(objA, key)) {
|
|
124
124
|
changes.push({ path: propPath, kind: 'added', after: objB[key] });
|
|
125
125
|
}
|
|
126
|
-
else if (!(key
|
|
126
|
+
else if (!Object.prototype.hasOwnProperty.call(objB, key)) {
|
|
127
127
|
changes.push({ path: propPath, kind: 'removed', before: objA[key] });
|
|
128
128
|
}
|
|
129
129
|
else {
|
package/dist/core/encoding.js
CHANGED
|
@@ -105,7 +105,7 @@ export function decodeText(input, codec, maxOutputBytes = DEFAULT_MAX_DECOMPRESS
|
|
|
105
105
|
const code = parseInt(entity.slice(1), 10);
|
|
106
106
|
return Number.isFinite(code) && code <= 0x10ffff ? String.fromCodePoint(code) : match;
|
|
107
107
|
}
|
|
108
|
-
return HTML_NAMED_DECODE[entity]
|
|
108
|
+
return Object.prototype.hasOwnProperty.call(HTML_NAMED_DECODE, entity) ? HTML_NAMED_DECODE[entity] : match;
|
|
109
109
|
});
|
|
110
110
|
case 'unicode':
|
|
111
111
|
return input.replace(/\\u\{([0-9a-fA-F]+)\}|\\u([0-9a-fA-F]{4})/g, (match, braced, fixed) => {
|
package/dist/core/jwt.js
CHANGED
|
@@ -62,29 +62,42 @@ export function decodeJwt(token, nowSec = Math.floor(Date.now() / 1000)) {
|
|
|
62
62
|
message: 'JWT signature segment is empty.',
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
+
const safeIso = (epochSec) => {
|
|
66
|
+
const ms = epochSec * 1000;
|
|
67
|
+
if (!Number.isFinite(ms))
|
|
68
|
+
return undefined;
|
|
69
|
+
const d = new Date(ms);
|
|
70
|
+
return Number.isNaN(d.getTime()) ? undefined : d.toISOString();
|
|
71
|
+
};
|
|
65
72
|
if (typeof payload.iat === 'number') {
|
|
66
|
-
|
|
73
|
+
const iso = safeIso(payload.iat);
|
|
74
|
+
if (iso)
|
|
75
|
+
timestamps.iat = iso;
|
|
67
76
|
}
|
|
68
77
|
if (typeof payload.nbf === 'number') {
|
|
69
|
-
|
|
78
|
+
const iso = safeIso(payload.nbf);
|
|
79
|
+
if (iso)
|
|
80
|
+
timestamps.nbf = iso;
|
|
70
81
|
timestamps.notYetValid = nowSec < payload.nbf;
|
|
71
82
|
if (timestamps.notYetValid) {
|
|
72
83
|
audit.push({
|
|
73
84
|
severity: 'warning',
|
|
74
85
|
code: 'NOT_YET_VALID',
|
|
75
|
-
message: `Token is not valid yet (nbf: ${timestamps.nbf}).`,
|
|
86
|
+
message: `Token is not valid yet (nbf: ${timestamps.nbf ?? payload.nbf}).`,
|
|
76
87
|
});
|
|
77
88
|
}
|
|
78
89
|
}
|
|
79
90
|
if (typeof payload.exp === 'number') {
|
|
80
|
-
|
|
91
|
+
const iso = safeIso(payload.exp);
|
|
92
|
+
if (iso)
|
|
93
|
+
timestamps.exp = iso;
|
|
81
94
|
timestamps.expiresInSeconds = payload.exp - nowSec;
|
|
82
95
|
timestamps.expired = nowSec >= payload.exp;
|
|
83
96
|
if (timestamps.expired) {
|
|
84
97
|
audit.push({
|
|
85
98
|
severity: 'warning',
|
|
86
99
|
code: 'TOKEN_EXPIRED',
|
|
87
|
-
message: `Token expired at ${timestamps.exp}.`,
|
|
100
|
+
message: `Token expired at ${timestamps.exp ?? payload.exp}.`,
|
|
88
101
|
});
|
|
89
102
|
}
|
|
90
103
|
else if (typeof payload.iat === 'number' && payload.exp - payload.iat > 86400 * 30) {
|
|
@@ -98,7 +111,7 @@ export function decodeJwt(token, nowSec = Math.floor(Date.now() / 1000)) {
|
|
|
98
111
|
audit.push({
|
|
99
112
|
severity: 'pass',
|
|
100
113
|
code: 'VALID_EXP',
|
|
101
|
-
message: `Expiration claim set (${timestamps.exp}).`,
|
|
114
|
+
message: `Expiration claim set (${timestamps.exp ?? payload.exp}).`,
|
|
102
115
|
});
|
|
103
116
|
}
|
|
104
117
|
}
|
|
@@ -190,8 +203,8 @@ export function verifyJwt(token, secretOrPublicKey, options = {}) {
|
|
|
190
203
|
decoded,
|
|
191
204
|
};
|
|
192
205
|
}
|
|
193
|
-
// Prevent RSA/EC public-key-as-HMAC algorithm confusion when PEM key is passed with HS*
|
|
194
|
-
if (alg in HMAC_ALGOS && /-----BEGIN (
|
|
206
|
+
// Prevent RSA/EC public-key or X.509 certificate-as-HMAC algorithm confusion when PEM key/cert is passed with HS*
|
|
207
|
+
if (alg in HMAC_ALGOS && /-----BEGIN (?:(?:RSA |EC )?PUBLIC KEY|CERTIFICATE)-----/.test(secretOrPublicKey)) {
|
|
195
208
|
return {
|
|
196
209
|
valid: false,
|
|
197
210
|
signatureValid: false,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as crypto from 'node:crypto';
|
|
2
2
|
import { decodeJwt } from './jwt.js';
|
|
3
|
+
import { isDangerousKey, timingSafeEqualStr } from './security.js';
|
|
3
4
|
export function computePkceS256Challenge(codeVerifier) {
|
|
4
5
|
if (codeVerifier.length < 43 || codeVerifier.length > 128) {
|
|
5
6
|
throw new Error('RFC 7636 code_verifier length must be between 43 and 128 characters');
|
|
@@ -16,6 +17,9 @@ export function generatePkceBundle(options = {}) {
|
|
|
16
17
|
let authorizationUrl;
|
|
17
18
|
if (options.authorizationEndpoint && options.authorizationEndpoint.trim()) {
|
|
18
19
|
const u = new URL(options.authorizationEndpoint.trim());
|
|
20
|
+
if (u.protocol !== 'https:' && u.protocol !== 'http:') {
|
|
21
|
+
throw new Error('Authorization endpoint must use https:// or http://');
|
|
22
|
+
}
|
|
19
23
|
u.searchParams.set('response_type', 'code');
|
|
20
24
|
if (options.clientId)
|
|
21
25
|
u.searchParams.set('client_id', options.clientId);
|
|
@@ -67,7 +71,7 @@ export function analyzeOAuthCallback(callbackUrl, expected = {}) {
|
|
|
67
71
|
}
|
|
68
72
|
let stateMatches;
|
|
69
73
|
if (expected.state) {
|
|
70
|
-
stateMatches = state === expected.state;
|
|
74
|
+
stateMatches = typeof state === 'string' && timingSafeEqualStr(state, expected.state);
|
|
71
75
|
securityFindings.push({
|
|
72
76
|
severity: stateMatches ? 'pass' : 'fail',
|
|
73
77
|
message: stateMatches
|
|
@@ -236,13 +240,14 @@ function decodeBufferInternal(buf, schemas, msgDef, depth = 0) {
|
|
|
236
240
|
while (pos < buf.length) {
|
|
237
241
|
const tagRes = readVarint(buf, pos);
|
|
238
242
|
pos = tagRes.nextOffset;
|
|
239
|
-
const
|
|
240
|
-
const
|
|
241
|
-
const wireType = tag & 0x07;
|
|
243
|
+
const fieldBig = tagRes.value >> 3n;
|
|
244
|
+
const wireType = Number(tagRes.value & 7n);
|
|
242
245
|
const wireTypeName = WIRE_TYPE_NAMES[wireType];
|
|
243
|
-
|
|
244
|
-
|
|
246
|
+
// Official Protobuf field numbers are 1..536,870,911 (2^29 - 1)
|
|
247
|
+
if (!wireTypeName || fieldBig <= 0n || fieldBig > 536870911n) {
|
|
248
|
+
throw new Error(`Invalid Protobuf tag (field=${fieldBig.toString()}, wireType=${wireType}) at offset ${pos}`);
|
|
245
249
|
}
|
|
250
|
+
const fieldNumber = Number(fieldBig);
|
|
246
251
|
const def = msgDef?.fields.get(fieldNumber);
|
|
247
252
|
const entry = {
|
|
248
253
|
fieldNumber,
|
|
@@ -345,10 +350,11 @@ function decodeBufferInternal(buf, schemas, msgDef, depth = 0) {
|
|
|
345
350
|
return fields;
|
|
346
351
|
}
|
|
347
352
|
function buildMappedObject(fields) {
|
|
348
|
-
const out =
|
|
353
|
+
const out = Object.create(null);
|
|
349
354
|
for (const f of fields) {
|
|
350
|
-
const
|
|
351
|
-
|
|
355
|
+
const rawKey = f.fieldName ?? `field_${f.fieldNumber}`;
|
|
356
|
+
const key = isDangerousKey(rawKey) ? `field_${f.fieldNumber}` : rawKey;
|
|
357
|
+
if (Object.prototype.hasOwnProperty.call(out, key)) {
|
|
352
358
|
const prev = out[key];
|
|
353
359
|
out[key] = Array.isArray(prev) ? [...prev, f.value] : [prev, f.value];
|
|
354
360
|
}
|
|
@@ -356,7 +362,7 @@ function buildMappedObject(fields) {
|
|
|
356
362
|
out[key] = f.value;
|
|
357
363
|
}
|
|
358
364
|
}
|
|
359
|
-
return out;
|
|
365
|
+
return Object.assign({}, out);
|
|
360
366
|
}
|
|
361
367
|
/**
|
|
362
368
|
* Decodes raw binary Protobuf payloads (hex or base64) into structured wire fields
|
package/dist/core/regex.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Script } from 'node:vm';
|
|
1
|
+
import { createContext, Script } from 'node:vm';
|
|
2
|
+
import { sanitizeObject } from './security.js';
|
|
2
3
|
export const REGEX_PRESETS = [
|
|
3
4
|
{
|
|
4
5
|
id: 'email',
|
|
@@ -310,6 +311,9 @@ export function testRegex(pattern, flags, text, options = {}) {
|
|
|
310
311
|
if (text.length > 250_000) {
|
|
311
312
|
throw new Error('Test input exceeds 250,000 character safety limit');
|
|
312
313
|
}
|
|
314
|
+
if (typeof options.replacement === 'string' && options.replacement.length > 10_000) {
|
|
315
|
+
throw new Error('Replacement string exceeds 10,000 character safety limit');
|
|
316
|
+
}
|
|
313
317
|
const sanitizedFlags = Array.from(new Set(flags.split('').filter((f) => VALID_FLAGS.has(f)))).join('');
|
|
314
318
|
// Validate regex syntax upfront
|
|
315
319
|
new RegExp(pattern, sanitizedFlags);
|
|
@@ -326,8 +330,9 @@ export function testRegex(pattern, flags, text, options = {}) {
|
|
|
326
330
|
maxMatches,
|
|
327
331
|
result: { matches: [], truncated: false, replaced: undefined },
|
|
328
332
|
};
|
|
333
|
+
const ctx = createContext(sandbox, { codeGeneration: { strings: false, wasm: false } });
|
|
329
334
|
try {
|
|
330
|
-
REGEX_RUNNER_SCRIPT.
|
|
335
|
+
REGEX_RUNNER_SCRIPT.runInContext(ctx, { timeout: timeoutMs });
|
|
331
336
|
}
|
|
332
337
|
catch (err) {
|
|
333
338
|
const msg = err.message || '';
|
|
@@ -337,11 +342,15 @@ export function testRegex(pattern, flags, text, options = {}) {
|
|
|
337
342
|
throw err;
|
|
338
343
|
}
|
|
339
344
|
const executionMs = Math.round((performance.now() - start) * 100) / 100;
|
|
345
|
+
const cleanMatches = sandbox.result.matches.map((m) => ({
|
|
346
|
+
...m,
|
|
347
|
+
namedGroups: sanitizeObject(m.namedGroups),
|
|
348
|
+
}));
|
|
340
349
|
return {
|
|
341
350
|
pattern,
|
|
342
351
|
flags: sanitizedFlags,
|
|
343
|
-
matches:
|
|
344
|
-
matchCount:
|
|
352
|
+
matches: cleanMatches,
|
|
353
|
+
matchCount: cleanMatches.length,
|
|
345
354
|
truncated: sandbox.result.truncated,
|
|
346
355
|
...(sandbox.result.replaced !== undefined ? { replaced: sandbox.result.replaced } : {}),
|
|
347
356
|
executionMs,
|
package/dist/core/secrets.js
CHANGED
|
@@ -311,9 +311,10 @@ function parseIgnoreFile(ignorePath) {
|
|
|
311
311
|
if (!clean)
|
|
312
312
|
continue;
|
|
313
313
|
const escaped = clean
|
|
314
|
+
.replace(/\*+/g, (stars) => (stars.length >= 2 ? '\0GLOBSTAR\0' : '\0STAR\0'))
|
|
314
315
|
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
315
|
-
.replace(
|
|
316
|
-
.replace(
|
|
316
|
+
.replace(/(?:\0GLOBSTAR\0\/?)+/g, '.*')
|
|
317
|
+
.replace(/\0STAR\0/g, '[^/]*');
|
|
317
318
|
regexes.push(new RegExp(`(^|/)${escaped}($|/)`));
|
|
318
319
|
}
|
|
319
320
|
return regexes;
|
|
@@ -344,6 +345,9 @@ export function scanDirectory(targetDir, options) {
|
|
|
344
345
|
let scannedFiles = 0;
|
|
345
346
|
let skippedFiles = 0;
|
|
346
347
|
if (stat.isFile()) {
|
|
348
|
+
if (stat.size > maxFileBytes) {
|
|
349
|
+
throw new Error(`File exceeds max scan size (${maxFileBytes} bytes): ${targetDir}`);
|
|
350
|
+
}
|
|
347
351
|
const content = fs.readFileSync(rootDir, 'utf8');
|
|
348
352
|
const res = scanSecrets(content, { checkHighEntropy: options?.checkHighEntropy !== false });
|
|
349
353
|
scannedFiles = 1;
|
|
@@ -545,15 +549,15 @@ export function scanGitStaged(targetDir = '.', options) {
|
|
|
545
549
|
* for direct upload to GitHub Code Scanning (`github/codeql-action/upload-sarif`).
|
|
546
550
|
* Raw secrets are NEVER written into SARIF — only masked fingerprints.
|
|
547
551
|
*/
|
|
548
|
-
export function formatSecretsAsSarif(findings, toolVersion = '1.
|
|
552
|
+
export function formatSecretsAsSarif(findings, toolVersion = '2.1.1') {
|
|
549
553
|
const rulesMap = new Map();
|
|
550
554
|
for (const r of SECRET_RULES) {
|
|
551
555
|
rulesMap.set(r.id, { id: r.id, name: r.name, severity: r.severity });
|
|
552
556
|
}
|
|
553
|
-
rulesMap.set('
|
|
554
|
-
id: '
|
|
555
|
-
name: 'High-Entropy Secret
|
|
556
|
-
severity: '
|
|
557
|
+
rulesMap.set('HIGH_ENTROPY_TOKEN', {
|
|
558
|
+
id: 'HIGH_ENTROPY_TOKEN',
|
|
559
|
+
name: 'High-Entropy Secret Candidate',
|
|
560
|
+
severity: 'medium',
|
|
557
561
|
});
|
|
558
562
|
const levelFor = (sev) => sev === 'critical' ? 'error' : sev === 'high' ? 'warning' : 'note';
|
|
559
563
|
return {
|
package/dist/core/security.js
CHANGED
|
@@ -97,9 +97,13 @@ function isPrivateIpv4Int(ipInt) {
|
|
|
97
97
|
// 192.0.0.0/24 (IETF protocol assignments)
|
|
98
98
|
if (a === 192 && b === 0 && ((ipInt >>> 8) & 0xff) === 0)
|
|
99
99
|
return true;
|
|
100
|
-
// 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 (TEST-NET)
|
|
100
|
+
// 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 (TEST-NET-1/2/3)
|
|
101
101
|
if (a === 192 && b === 0 && ((ipInt >>> 8) & 0xff) === 2)
|
|
102
102
|
return true;
|
|
103
|
+
if (a === 198 && b === 51 && ((ipInt >>> 8) & 0xff) === 100)
|
|
104
|
+
return true;
|
|
105
|
+
if (a === 203 && b === 0 && ((ipInt >>> 8) & 0xff) === 113)
|
|
106
|
+
return true;
|
|
103
107
|
// 192.168.0.0/16 (RFC1918)
|
|
104
108
|
if (a === 192 && b === 168)
|
|
105
109
|
return true;
|
|
@@ -169,11 +173,24 @@ export function isPrivateIp(rawIp) {
|
|
|
169
173
|
const mappedV4 = (((g6 & 0xffff) << 16) | (g7 & 0xffff)) >>> 0;
|
|
170
174
|
return isPrivateIpv4Int(mappedV4);
|
|
171
175
|
}
|
|
172
|
-
// 64:ff9b::/96 (NAT64 well-known
|
|
176
|
+
// 64:ff9b::/96 (NAT64 well-known) & 64:ff9b:1::/48 (RFC 8215 NAT64 local-use)
|
|
173
177
|
if (g0 === 0x0064 && g1 === 0xff9b && g2 === 0 && g3 === 0 && g4 === 0 && g5 === 0) {
|
|
174
178
|
const mappedV4 = (((g6 & 0xffff) << 16) | (g7 & 0xffff)) >>> 0;
|
|
175
179
|
return isPrivateIpv4Int(mappedV4);
|
|
176
180
|
}
|
|
181
|
+
if (g0 === 0x0064 && g1 === 0xff9b && g2 === 0x0001)
|
|
182
|
+
return true;
|
|
183
|
+
// 2002::/16 (6to4 — embeds arbitrary IPv4 in g1:g2, e.g. 2002:7f00:0001::1 -> 127.0.0.1)
|
|
184
|
+
if (g0 === 0x2002) {
|
|
185
|
+
const embeddedV4 = (((g1 & 0xffff) << 16) | (g2 & 0xffff)) >>> 0;
|
|
186
|
+
return isPrivateIpv4Int(embeddedV4);
|
|
187
|
+
}
|
|
188
|
+
// 100::/64 (RFC 6666 Discard-Only)
|
|
189
|
+
if (g0 === 0x0100 && g1 === 0 && g2 === 0 && g3 === 0)
|
|
190
|
+
return true;
|
|
191
|
+
// 2001::/32 (Teredo tunneling)
|
|
192
|
+
if (g0 === 0x2001 && g1 === 0x0000)
|
|
193
|
+
return true;
|
|
177
194
|
// fc00::/7 (Unique Local Address)
|
|
178
195
|
if ((g0 & 0xfe00) === 0xfc00)
|
|
179
196
|
return true;
|
|
@@ -221,7 +238,7 @@ export async function validateProxyTargetUrl(rawUrl, options = {}) {
|
|
|
221
238
|
if (url.username || url.password) {
|
|
222
239
|
throw new Error('Embedded URL credentials are not permitted; use the Authorization header instead');
|
|
223
240
|
}
|
|
224
|
-
const hostname = url.hostname.toLowerCase().replace(/^\[|\]$/g, '');
|
|
241
|
+
const hostname = url.hostname.toLowerCase().replace(/^\[|\]$/g, '').replace(/\.+$/, '');
|
|
225
242
|
if (!hostname) {
|
|
226
243
|
throw new Error('URL hostname is required');
|
|
227
244
|
}
|
package/dist/core/tls.js
CHANGED
|
@@ -48,8 +48,8 @@ function inspectX509Object(cert) {
|
|
|
48
48
|
subject: cert.subject,
|
|
49
49
|
issuer: cert.issuer,
|
|
50
50
|
serialNumber: cert.serialNumber,
|
|
51
|
-
validFrom: new Date(validFromMs).toISOString(),
|
|
52
|
-
validTo: new Date(validToMs).toISOString(),
|
|
51
|
+
validFrom: Number.isFinite(validFromMs) ? new Date(validFromMs).toISOString() : cert.validFrom,
|
|
52
|
+
validTo: Number.isFinite(validToMs) ? new Date(validToMs).toISOString() : cert.validTo,
|
|
53
53
|
daysRemaining,
|
|
54
54
|
expired,
|
|
55
55
|
expiringSoon,
|
|
@@ -87,6 +87,9 @@ export async function inspectRemoteTls(rawTarget, options = {}) {
|
|
|
87
87
|
throw new Error('Target domain or HTTPS URL is required');
|
|
88
88
|
const urlCandidate = /^https?:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
|
|
89
89
|
const parsed = new URL(urlCandidate);
|
|
90
|
+
if (parsed.username || parsed.password) {
|
|
91
|
+
throw new Error('Embedded URL credentials are not permitted in TLS inspection target');
|
|
92
|
+
}
|
|
90
93
|
const port = options.port ?? (parsed.port ? Number(parsed.port) : 443);
|
|
91
94
|
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
92
95
|
throw new Error(`Invalid TCP port "${port}"`);
|
package/dist/server/app.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { PluginLoader } from './plugin-loader.js';
|
|
|
4
4
|
import { RecorderStore } from './recorder-store.js';
|
|
5
5
|
import { WebhookStore } from './webhook-store.js';
|
|
6
6
|
import { WorkspaceStore } from './workspace-store.js';
|
|
7
|
-
export declare const DEVANVIL_VERSION = "2.1.
|
|
7
|
+
export declare const DEVANVIL_VERSION = "2.1.1";
|
|
8
8
|
export interface DevAnvilServerOptions {
|
|
9
9
|
host?: string;
|
|
10
10
|
port?: number;
|