实现示例function norm(p: string): string { return p.replace(/\\/g,'/').replace(/\/+/g,'/') }
function allowedPath(p: string, allowRoots: string[]): boolean {
const n = norm(p)
if (n.includes('..')) return false
if (/^\//.test(n)) return false
return allowRoots.some(r => n.startsWith(r.endsWith('/') ? r : r + '/'))
}
type Entry = { path: string; data: Uint8Array }
function filter(entries: Entry[], allowRoots: string[], allowExts: Set<string>): Entry[] {
const out: Entry[] = []
for (const e of entries) {
if (!allowedPath(e.path, allowRoots)) continue
const ext = (e.path.split('.').pop() || '').toLowerCase()
if (!allowExts.has(ext)) continue
out.push(e)
}
return out
}
审计与CI门禁审计记录包含被拒绝路径与文件扩展;异常阻断并输出证据。允许目录与扩展清单需审批与版本化管理。

发表评论 取消回复