Skip to content

[Security] Implement Client-Side Input Sanitization and XSS Prevention for All Forms #2575

Description

@knoxiboy

Title: [Security] Implement Client-Side Input Sanitization and XSS Prevention for All Forms

Description
The login (login.js), registration (register.js), checkout (checkout.js), and contact forms accept user input without sanitization. Script injection via form fields could lead to XSS attacks stored in localStorage or rendered in DOM.

Motivation
Even in a frontend-only application, XSS through innerHTML assignments or localStorage poisoning can steal session data or redirect users to phishing sites.

Implementation Suggestions

  1. Create a sanitize.js utility module with functions: escapeHTML(), sanitizeInput(), validateEmail().
  2. Import and apply sanitization to all form submissions in login.js, register.js, checkout.js, and contact.html.
  3. Replace all innerHTML assignments with textContent where dynamic user data is rendered.
  4. Add Content-Security-Policy meta tag to all HTML files to block inline scripts.

Level: Critical
Affected Files: sanitize.js (new), login.js, register.js, checkout.js, all .html files

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions