Skip to content

fix: add Content-Security-Policy headers and tighten email validation#2

Open
borice1984 wants to merge 1 commit into
wilwaldon:mainfrom
borice1984:fix/security-csp-headers
Open

fix: add Content-Security-Policy headers and tighten email validation#2
borice1984 wants to merge 1 commit into
wilwaldon:mainfrom
borice1984:fix/security-csp-headers

Conversation

@borice1984
Copy link
Copy Markdown

What

Two security hardening changes to the static template:

  1. CSP meta tag added to all six HTML pages
  2. Email regex tightened in forms.js

Why

Content-Security-Policy

The static template had no CSP whatsoever. Without it, any injected script (via a browser extension, ad network compromise, or XSS vector) runs unconstrained. Adding a <meta http-equiv="Content-Security-Policy"> tag is the right approach for S3-hosted sites since you can't set HTTP response headers there.

The policy applied:

default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com data:; img-src 'self' data: https:; frame-src https://www.google.com; connect-src 'self' https://formspree.io; object-src 'none'; base-uri 'self'
  • unsafe-inline on style-src is required because the template uses inline style= attributes for layout elements
  • frame-src covers Google Maps embeds
  • connect-src includes formspree.io to support the form submission PR

Email regex

The previous pattern /^[^\s@]+@[^\s@]+\.[^\s@]+$/ allowed addresses like foo@bar.123 or a@b.c d. Tightened to /^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/ which requires a valid TLD of at least 2 alpha characters.

Files changed

  • templates/static/base/index.html
  • templates/static/base/contact.html
  • templates/static/base/page-2.html
  • templates/static/base/page-3.html
  • templates/static/base/page-4.html
  • templates/static/base/404.html
  • templates/static/base/js/forms.js

Adds a CSP meta tag to all six static template pages to prevent
inline script injection and restrict resource origins. Tightens the
email regex in forms.js to reject addresses with invalid TLD formats
(e.g. missing dot, numeric-only TLD) that the previous loose pattern
allowed through.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant