fix: add Content-Security-Policy headers and tighten email validation#2
Open
borice1984 wants to merge 1 commit into
Open
fix: add Content-Security-Policy headers and tighten email validation#2borice1984 wants to merge 1 commit into
borice1984 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two security hardening changes to the static template:
forms.jsWhy
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:
unsafe-inlineonstyle-srcis required because the template uses inlinestyle=attributes for layout elementsframe-srccovers Google Maps embedsconnect-srcincludesformspree.ioto support the form submission PREmail regex
The previous pattern
/^[^\s@]+@[^\s@]+\.[^\s@]+$/allowed addresses likefoo@bar.123ora@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.htmltemplates/static/base/contact.htmltemplates/static/base/page-2.htmltemplates/static/base/page-3.htmltemplates/static/base/page-4.htmltemplates/static/base/404.htmltemplates/static/base/js/forms.js