Files
homebrewery-oidc/server/fork/git/validate.js
T
dev-bot BotandClaude Sonnet 5.5 448c67912f
CI / App (npm ci + Build, ESLint, Stylelint, Jest) (push) Successful in 3m25s
CI / Storage (mongo) (push) Successful in 1m24s
CI / Storage (postgres) (push) Successful in 1m13s
Image / Image bauen und pushen (push) Successful in 1m3s
feat(git): Git-Backend über HTTPS + PAT (ADR 0003, FLW-86) (#19)
Repositories gitConnections/brewGitLinks (Mongo/PG), Krypto, SSRF-Policy mit net.BlockList, git-Client ohne Arbeitskopie, Sync/Konflikte, /api/git/*, Client (Verbindungen, Git-Status, Konfliktdialog), Autosave 60 s für Git-Brews (F6), Tests und Doku.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Dev (Paperclip) <dev-bot@noreply.git.morlana.online>
2026-11-25 21:16:42 +00:00

40 lines
2.0 KiB
JavaScript

import { execFile } from 'child_process';
import { GitError } from './errors.js';
// Pfad- und Branch-Validierung (ADR 0003 §2).
export const validatePath = (p)=>{
const bad = (msg)=>{ throw new GitError('G08', `Ungültiger Pfad: ${msg}`); };
if(typeof p !== 'string' || !p) bad('leer');
if(p.length > 255) bad('länger als 255 Zeichen');
if(p.startsWith('/') || p.includes('\\') || /[\0-\x1f]/.test(p)) bad('nur relative Pfade mit / erlaubt');
const parts = p.split('/');
if(parts.some((s)=>s === '' || s === '.' || s === '..')) bad('kein .., . oder leere Segmente');
if(parts[0].toLowerCase() === '.git' || parts.some((s)=>s.toLowerCase() === '.git')) bad('nicht unter .git');
if(!p.endsWith('.md')) bad('Endung .md erforderlich');
return p;
};
// Ordner (ohne Endung-Pflicht), für brewDir/assetsDir und Dateilisten
export const validateDir = (d)=>{
if(d === '' || d === undefined || d === null) return '';
if(typeof d !== 'string' || d.length > 255 || d.startsWith('/') || d.includes('\\') || /[\0-\x1f]/.test(d))
throw new GitError('G08', 'Ungültiger Ordner.');
const parts = d.replace(/\/+$/, '').split('/');
if(parts.some((s)=>s === '' || s === '.' || s === '..' || s.toLowerCase() === '.git'))
throw new GitError('G08', 'Ungültiger Ordner.');
return parts.join('/');
};
// `git check-ref-format` auf refs/heads/<name> (nicht --branch: das expandiert z. B. "@{-1}").
export const validateBranch = (name)=>new Promise((resolve, reject)=>{
const bad = ()=>reject(new GitError('G08', 'Ungültiger Branch-Name.'));
if(typeof name !== 'string' || !name || name.length > 255 || name.startsWith('-') || /[\0-\x1f]/.test(name)) return bad();
execFile('git', ['check-ref-format', `refs/heads/${name}`], { timeout: 5000 }, (err)=>err ? bad() : resolve(name));
});
export const slugify = (title)=>{
const s = String(title || '').normalize('NFKD').replace(/[̀-ͯ]/g, '').toLowerCase()
.replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 80);
return s || 'brew';
};