Reject mismatched uploads; add local mock AI runner
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
75158c4449
commit
c59591ccb9
2 changed files with 13 additions and 1 deletions
|
|
@ -108,7 +108,11 @@ export function ingestUpload(
|
|||
throw new HttpError(413, 'too_large', `"${input.filename}" is larger than the ${Math.round(app.config.maxUploadBytes / 1048576)} MB upload limit.`);
|
||||
}
|
||||
const filename = path.basename(input.filename.replace(/\\/g, '/')).slice(0, 200) || 'upload';
|
||||
const kind = detectKind(filename, input.mime, input.bytes);
|
||||
let kind = detectKind(filename, input.mime, input.bytes);
|
||||
// A file whose name claims a binary format but whose bytes say otherwise (a renamed
|
||||
// executable, say) is refused here instead of being stored and failing later.
|
||||
if (kind === 'pdf' && !Buffer.from(input.bytes.subarray(0, 1024)).includes('%PDF')) kind = null;
|
||||
if ((kind === 'docx' || kind === 'pptx') && !(input.bytes[0] === 0x50 && input.bytes[1] === 0x4b) && !(input.bytes[0] === 0xd0 && input.bytes[1] === 0xcf)) kind = null;
|
||||
if (!kind) {
|
||||
throw new HttpError(415, 'unsupported_type', `"${filename}" is not a supported file type. Upload PDF, Word (.docx), PowerPoint (.pptx), text, Markdown, or an image.`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue