generated from nhcarrigan/template
feat: add data URL validation
This commit is contained in:
@@ -4,6 +4,13 @@
|
|||||||
* @author Naomi Carrigan
|
* @author Naomi Carrigan
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates that a URL is a proper base64 data string.
|
||||||
|
*/
|
||||||
|
export function validateDataUrl(url: string): boolean {
|
||||||
|
return /^data:image\/(jpeg|png|gif|webp|svg\+xml);base64,[A-Za-z0-9+/=]+$/.test(url);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates that a URL is safe and points to an allowed protocol.
|
* Validates that a URL is safe and points to an allowed protocol.
|
||||||
* Prevents javascript:, data:, vbscript:, and file: URLs.
|
* Prevents javascript:, data:, vbscript:, and file: URLs.
|
||||||
@@ -83,4 +90,5 @@ export const MAX_LENGTHS = {
|
|||||||
NOTES: 5000,
|
NOTES: 5000,
|
||||||
TAGS: 50, // per tag
|
TAGS: 50, // per tag
|
||||||
ISBN: 50,
|
ISBN: 50,
|
||||||
|
DATA_URL: 5 * 1024 * 1024, // 5MB in bytes (not chars)
|
||||||
} as const;
|
} as const;
|
||||||
|
|||||||
Reference in New Issue
Block a user