fix(domain,app): own-key lookups for untrusted ids in the v2 migration, attachment and PDF size caps; EVAL-011, journal, TODO
This commit is contained in:
1 parent
17a6d9b323
commit
e7f4167ada
8 files changed
+76
-5
No files matched your search
@@ -65,10 +65,16 @@ export async function extractReportJson(
|
||||
return parseAttachment(fallback, map)
|
||||
}
|
||||
|
||||
/** Hard ceiling on an attachment (inflated or not): a report is a few hundred KB at most. */
|
||||
const MAX_ATTACHMENT_BYTES = 16 * 1024 * 1024
|
||||
|
||||
function parseAttachment(
|
||||
bytes: Uint8Array,
|
||||
map: ReportMigrationMap,
|
||||
): ExtractedReport {
|
||||
if (bytes.byteLength > MAX_ATTACHMENT_BYTES) {
|
||||
throw new Error('attachment too large')
|
||||
}
|
||||
const data: unknown = JSON.parse(new TextDecoder().decode(bytes))
|
||||
const version =
|
||||
data !== null &&
|
||||
@@ -100,7 +106,7 @@ interface RawObj {
|
||||
* Hard ceiling on inflated attachment size. A valid report JSON is far
|
||||
* smaller; anything bigger is a decompression bomb or corruption.
|
||||
*/
|
||||
const MAX_INFLATED_BYTES = 16 * 1024 * 1024
|
||||
const MAX_INFLATED_BYTES = MAX_ATTACHMENT_BYTES
|
||||
|
||||
/** Exported for tests. Returns null on failure or when the cap is exceeded. */
|
||||
export async function inflateFlate(
|
||||
|
||||
@@ -31,10 +31,14 @@ export class ImportError extends Error {
|
||||
* through the reference sheet's map). The outcome says whether a migration
|
||||
* happened and how many zones or findings it could not place.
|
||||
*/
|
||||
/** A Faunosteo PDF weighs a few hundred KB; anything larger is not one. */
|
||||
export const MAX_PDF_BYTES = 50 * 1024 * 1024
|
||||
|
||||
export async function importReportFromPdf(
|
||||
pdfBytes: Uint8Array,
|
||||
map: ReportMigrationMap,
|
||||
): Promise<ExtractedReport> {
|
||||
if (pdfBytes.byteLength > MAX_PDF_BYTES) throw new ImportError('invalid_pdf')
|
||||
let pdfDoc: PDFDocument
|
||||
try {
|
||||
pdfDoc = await PDFDocument.load(pdfBytes, { ignoreEncryption: true })
|
||||
|
||||
Reference in new issue
Block a user