test(e2e): set a user password and revoke a delegation from the web ui

- test(e2e): set a user password and revoke a delegation from the web ui
- test(e2e): switch a dynamic soa serial to a managed one through the ui
- test(e2e): match audit ledger routes on the decoded api path
- test(e2e): fuzz injection payloads in paths, filters and record data
This commit is contained in:
bryanpedini committed 2026-11-19 15:46:12 +01:00
1 parent 2a773e740f
commit 1cafcc759e
7 files changed
+433 -28

No files matched your search

+124
View File
@@ -0,0 +1,124 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2026 Bryan Joshua Pedini
import type { RecordType } from './records';
import type { Rng } from './rng';
export const SQL_INJECTION = "' OR '1'='1' -- ";
export const SCRIPT = '<script>x</script>';
export const PAYLOADS = [
SQL_INJECTION,
SCRIPT,
`${SCRIPT}${SQL_INJECTION}`,
"x'); DROP TABLE users; --",
'" OR ""="',
'"><img src=x onerror=alert(1)>',
"admin'--",
'1 UNION SELECT username FROM users',
] as const;
export const AUDIT_FILTER_KEYS = ['zone', 'actor', 'operation', 'kind', 'outcome', 'before_id', 'limit'] as const;
export const QUERY_KEYS = [...AUDIT_FILTER_KEYS, 'deleted'] as const;
export interface FuzzRecord {
name: unknown;
type: RecordType;
ttl: unknown;
data: Record<string, unknown>;
}
interface Field {
valid: readonly unknown[];
hostile: readonly unknown[];
}
const INTEGERS_HOSTILE: readonly unknown[] = [65536, 2147483648, -1, '10', 1.5, null, SQL_INJECTION];
const U16: Field = { valid: [0, 1, 10, 65535], hostile: INTEGERS_HOSTILE };
const TTL: Field = { valid: [0, 1, 300, 86400, 2147483647], hostile: [2147483648, -1, '300', 1.5, null, SQL_INJECTION] };
const TEXT: Field = {
valid: ["it's", 'a;b;c', '<b>bold</b>', 'say "hi"', SQL_INJECTION, SCRIPT, 'plain text', 'x'.repeat(300), '"><img src=x onerror=alert(1)>'],
hostile: ['', 'back\\slash', 'tab\there', 'café', 'nul\u0000byte', 'x'.repeat(4097), 7, null],
};
const IPV4: Field = { valid: ['192.0.2.55', '198.51.100.7', '203.0.113.200'], hostile: ['2001:db8::55', '256.0.0.1', '192.0.2.055', '::ffff:192.0.2.1', SQL_INJECTION, SCRIPT, '', 3221225985] };
const IPV6: Field = { valid: ['2001:db8::55', '2001:db8:0:0:0:0:0:56', '2001:DB8::57'], hostile: ['192.0.2.55', '::ffff:192.0.2.1', '2001:db8::g', SQL_INJECTION, SCRIPT, '', 1] };
const CAA_TAG: Field = { valid: ['issue', 'issuewild', 'iodef'], hostile: ['bad tag', SCRIPT, SQL_INJECTION, '', 'x'.repeat(256), 1] };
const CAA_FLAG: Field = { valid: [0, 128], hostile: [256, -1, '0', SQL_INJECTION, null] };
const SOA_TIMER: Field = { valid: [60, 3600, 604800, 2147483647], hostile: [0, -1, 2147483648, 4294967296, '3600', null, SQL_INJECTION] };
function hosts(zone: string): Field {
return {
valid: ['target.example.net.', `www.${zone}`, 'mail.example.net'],
hostile: ['single-label', SQL_INJECTION, SCRIPT, '-bad-.example.net.', 'a..b.example.net.', '', `${'x'.repeat(64)}.example.net.`, 'under score!.example.net.', 5],
};
}
function fields(zone: string, type: RecordType): Record<string, Field> {
const host = hosts(zone);
switch (type) {
case 'A':
return { ip: IPV4 };
case 'AAAA':
return { ip: IPV6 };
case 'CNAME':
case 'NS':
return { host };
case 'MX':
return { host: { valid: ['mail.example.net.', `mx.${zone}`], hostile: host.hostile }, preference: U16 };
case 'TXT':
return { text: TEXT };
case 'SRV':
return { priority: U16, weight: U16, port: U16, target: { valid: ['sip.example.net.', '.'], hostile: host.hostile } };
case 'CAA':
return { flag: CAA_FLAG, tag: CAA_TAG, value: { valid: TEXT.valid.filter((t) => t !== '' && String(t).length < 256), hostile: TEXT.hostile } };
case 'SOA':
return {
ns: { valid: ['ns1.example.net.', `ns1.${zone}`], hostile: host.hostile },
MBox: { valid: ['hostmaster.example.net.', `hostmaster.${zone}`], hostile: [...host.hostile, 'host@master@example.net'] },
refresh: SOA_TIMER,
retry: SOA_TIMER,
expire: SOA_TIMER,
minttl: SOA_TIMER,
};
}
}
function freshName(rng: Rng, type: RecordType, seq: number): string {
const label = `f${seq}${rng.string(5)}`;
const choices = type === 'SRV' ? [`_${label}._tcp`, `_${label}._udp`] : [label, `${label}.sub`, label.toUpperCase()];
if (type !== 'NS' && type !== 'SRV') choices.push(`*.${label}`);
if (type === 'NS' || type === 'MX' || type === 'TXT' || type === 'CAA') choices.push('@');
return rng.pick(choices);
}
const NAME_HOSTILE: readonly unknown[] = [SQL_INJECTION, SCRIPT, '', 'bad name', 'x'.repeat(64), '*bad', 'nul\u0000', 7, null];
export function fuzzRecord(rng: Rng, zone: string, type: RecordType, seq: number, mutate: boolean): FuzzRecord {
const spec = fields(zone, type);
const data: Record<string, unknown> = {};
for (const [key, field] of Object.entries(spec)) data[key] = rng.pick(field.valid);
const record: FuzzRecord = { name: type === 'SOA' ? '@' : freshName(rng, type, seq), type, ttl: rng.pick(TTL.valid), data };
if (!mutate) return record;
const keys = Object.keys(spec);
const target = rng.weighted<string>([
['name', 2],
['ttl', 2],
['data', 6],
['missing', 1],
['extra', 1],
]);
if (target === 'name') record.name = rng.pick(NAME_HOSTILE);
else if (target === 'ttl') record.ttl = rng.pick(TTL.hostile);
else if (target === 'missing') delete data[rng.pick(keys)];
else if (target === 'extra') data[rng.pick(['serial', 'Ttl', 'comment', 'ip', 'host'])] = rng.pick(PAYLOADS);
else {
const key = rng.pick(keys);
data[key] = rng.pick(spec[key].hostile);
}
return record;
}
export function soaBody(record: FuzzRecord): Record<string, unknown> {
const d = record.data;
return { ns: d.ns, mbox: d.MBox, ttl: record.ttl, refresh: d.refresh, retry: d.retry, expire: d.expire, minttl: d.minttl };
}
+7 -7
View File
@@ -81,11 +81,12 @@ export interface RouteMatch {
targetUser: string | null;
}
function decode(segment: string): string | null {
export function decodedApiPath(path: string): string {
const raw = path.slice('/api/v1'.length).split('?')[0];
try {
return decodeURIComponent(segment);
return decodeURIComponent(raw);
} catch {
return null;
return raw;
}
}
@@ -102,11 +103,11 @@ export function matchRoute(method: string, apiPath: string): RouteMatch | null {
if (m !== method.toUpperCase()) continue;
const match = re.exec(apiPath);
if (!match) continue;
const groups = match.slice(1).map((s) => decode(s));
const groups = match.slice(1);
const out: RouteMatch = { operation, zone: null, recordId: null, targetUser: null };
targets.forEach((t, i) => {
const v = groups[i];
if (v === null || v === undefined) return;
if (v === undefined) return;
if (t === 'zone') out.zone = normalizeZoneParam(v);
if (t === 'record' && /^\+?[0-9]+$/.test(v)) {
const id = Number(v);
@@ -204,8 +205,7 @@ export class AuditLedger {
api(x: ApiExchange): void {
if (!x.path.startsWith('/api/v1/') && x.path !== '/api/v1') return;
const apiPath = x.path.slice('/api/v1'.length).split('?')[0];
const route = matchRoute(x.method, apiPath);
const route = matchRoute(x.method, decodedApiPath(x.path));
if (!x.sessionValid || x.status === 401 || x.crossOrigin) {
this.skipped++;
return;