Runner: Eingabepruefung gehaertet (R8)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aeb08580bb
commit
8588e63124
3 files changed
+28
-9
No files matched your search
@@ -6,15 +6,16 @@ const RE_BRANCH = /^[\w./-]{1,100}$/;
|
||||
const RE_ENV = /^[A-Z_][A-Z0-9_]*$/;
|
||||
const MODES = ['auto', 'build', 'dev'];
|
||||
|
||||
export const isValidRunId = (s) => typeof s === 'string' && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(s);
|
||||
export const isValidSub = (s) => typeof s === 'string' && RE_SUB.test(s);
|
||||
|
||||
export function validateJob(body) {
|
||||
if (!body || typeof body !== 'object' || Array.isArray(body)) return { ok: false, error: 'Ungültige Anfrage' };
|
||||
const { sub, repo, sha, branch } = body;
|
||||
if (!isValidSub(sub)) return { ok: false, error: 'Ungültige Subdomain' };
|
||||
if (typeof repo !== 'string' || !RE_REPO.test(repo)) return { ok: false, error: 'Ungültiges Repository' };
|
||||
if (typeof repo !== 'string' || !RE_REPO.test(repo) || repo.split('/').some((x) => x === '.' || x === '..' || x.startsWith('-'))) return { ok: false, error: 'Ungültiges Repository' };
|
||||
if (typeof sha !== 'string' || !RE_SHA.test(sha)) return { ok: false, error: 'Ungültiger Commit' };
|
||||
if (typeof branch !== 'string' || !RE_BRANCH.test(branch) || branch.includes('..')) return { ok: false, error: 'Ungültiger Branch' };
|
||||
if (typeof branch !== 'string' || !RE_BRANCH.test(branch) || branch.startsWith('-') || branch.includes('..') || branch.endsWith('/') || branch.endsWith('.lock')) return { ok: false, error: 'Ungültiger Branch' };
|
||||
const mode = body.mode === undefined || body.mode === '' ? 'auto' : body.mode;
|
||||
if (!MODES.includes(mode)) return { ok: false, error: 'Ungültiger Modus' };
|
||||
let index;
|
||||
@@ -37,7 +38,8 @@ export function validateJob(body) {
|
||||
env[n] = v;
|
||||
}
|
||||
}
|
||||
const job = { ...body, sub, repo, sha, branch, mode, env };
|
||||
if (index !== undefined) job.index = index; else delete job.index;
|
||||
// Whitelist: keine ungeprüften Client-Felder im Job
|
||||
const job = { sub, repo, sha, branch, mode, env };
|
||||
if (index !== undefined) job.index = index;
|
||||
return { ok: true, job };
|
||||
}
|
||||
Reference in new issue
Block a user