forked from syntaxbullet/AuroraBot-discord
feat: Implement secure static file serving with path traversal protection and XSS prevention for template titles.
This commit is contained in:
14
src/web/utils/html.ts
Normal file
14
src/web/utils/html.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
/**
|
||||
* Escapes unsafe characters in a string to prevent XSS.
|
||||
* @param unsafe - The raw string to escape.
|
||||
* @returns The escaped string safe for HTML insertion.
|
||||
*/
|
||||
export function escapeHtml(unsafe: string): string {
|
||||
return unsafe
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
Reference in New Issue
Block a user