security: fix XSS vulnerabilities in GanttChart and AuditPage

- Add escapeHtml utility function for HTML entity encoding
- Apply escapeHtml to GanttChart popup HTML template
- Apply escapeHtml to AuditPage PDF export HTML template

This prevents potential XSS attacks if task names, user names,
or other dynamic content contains malicious HTML/JavaScript.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beabigegg
2026-01-13 21:26:06 +08:00
parent a78d878865
commit 3da0bf5c3a
3 changed files with 36 additions and 9 deletions

View File

@@ -0,0 +1,24 @@
/**
* Escapes HTML special characters to prevent XSS attacks.
* Use this when inserting dynamic content into HTML strings.
*/
export function escapeHtml(unsafe: string | null | undefined): string {
if (unsafe == null) return ''
return String(unsafe)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;')
}
/**
* Escapes HTML for use in HTML attributes.
* More restrictive than escapeHtml - also escapes backticks and equals.
*/
export function escapeAttr(unsafe: string | null | undefined): string {
if (unsafe == null) return ''
return escapeHtml(unsafe)
.replace(/`/g, '&#96;')
.replace(/=/g, '&#61;')
}