Files
orca/src/relay/plugin-source-limit.ts
T
2026-05-14 16:06:23 -07:00

13 lines
497 B
TypeScript

export const PLUGIN_SOURCE_MAX_BYTES = 256 * 1024
export function assertPluginSourceUnderByteCap(fieldName: string, value: unknown): void {
if (typeof value !== 'string') {
return
}
// Why: the relay receives JSON strings over the wire; cap actual UTF-8
// bytes instead of UTF-16 code units so non-ASCII source cannot bypass it.
if (Buffer.byteLength(value, 'utf8') > PLUGIN_SOURCE_MAX_BYTES) {
throw new Error(`${fieldName} exceeds ${PLUGIN_SOURCE_MAX_BYTES} byte cap`)
}
}