security: add HTTP security headers to next.config.mjs#2
Open
advikdivekar wants to merge 115 commits into
Open
security: add HTTP security headers to next.config.mjs#2advikdivekar wants to merge 115 commits into
advikdivekar wants to merge 115 commits into
Conversation
…ear Search Fixes PankajSingh34#43 - Added speedRef (useRef) to track latest speed value without closure issues - Updated increaseSpeed/decreaseSpeed to keep speedRef in sync with state - Binary Search: delay now reads from speedRef.current each recursive call - Linear Search: delay moved inside step() so it is re-read on every iteration
…essage colors Fixes PankajSingh34#44 - Added messageType state: 'success' | 'error' | 'warning' - Validation errors (empty fields, invalid input, unsorted array) → yellow/warning - Element not found (actual search result) → red/error - Element found → green/success - Replaced foundIndex-based color logic with messageType-driven messageClass
- Add isSortingRef to track active sort session - Add resolveRef to immediately unblock suspended async loop on reset - Replace raw setTimeout promises with cancellableDelay helper - Add isSortingRef.current guard checks inside sort loops - reset() now calls resolveRef.current() to exit pending promise instantly Fixes: stat counters doubling, flickering bars, race conditions when Reset is clicked mid-animation and sort is immediately restarted.
…-messages fix: correct wrong messages in stack quiz
… boxes Fixes PankajSingh34#86 - Added getFontSize() helper that returns text-lg, text-sm, or text-xs based on the string length of the displayed value - Applied to all 7 visualizers: bubble, insertion, selection, merge, quicksort, binary search, linear search - Prevents 3+ digit numbers and negative values from overflowing the fixed w-16 h-16 element boxes
…-reactive-animation fix: speed slider now reactive during active animation (Binary/Linear Search)
…de-button feat: add reusable CopyButton component for code snippets
…less-rate-limit-bypass [Security] Replace in-memory rate limiter with global Redis sliding window
…e-algorithm-ui Standardize algorithm visualization page layouts
…pgrst116 fix: unhandled PGRST116 error when fetching user progress
Add robust cancellation and full reset handling to all sorting visualizers
…overflow fix: dynamically scale font size for large and negative values in element boxes
Fixes PankajSingh34#85 - Added duplicate check using Set before starting the animation - If duplicates detected, shows clear warning message and blocks the search - Binary Search is only reliable on arrays with unique values
Guard Supabase initialization when env vars are missing
…-patch-12 Delete .github/workflows/IssueLabeler.yml
…-patch-13 Add AI issue labeler workflow
…-patch-14 Delete .github/workflows/labeler.yml
…-patch-15 Add labeler configuration for issue labeling
…-patch-16 Refactor labeler.yml regex patterns for labels
…-patch-17 Update ai-issue-labeler.yml
…-patch-18 Update ai-issue-labeler.yml
…-patch-19 Update labeler.yml
…-patch-20 Simplify step name in issue labeling workflow
…-patch-21 Disable versioned regex in issue labeler workflow
…-patch-22 Update issue labeler action to version 3.5
…-patch-23 Update ai-issue-labeler.yml
…ch Binary Search layout
…-actions-sorting style: Remove ArticleActions from all sorting visualizer pages to match Binary Search layout
The merge of main into security/http-security-headers left an unresolved conflict that inserted a second `const nextConfig` block inside the first one, making the file unparseable (SyntaxError on CI). Keeps the full six-header version (including CSP and HSTS) and removes the duplicate.
advikdivekar
force-pushed
the
security/http-security-headers
branch
from
May 24, 2026 05:08
7ac2660 to
611d425
Compare
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.
Problem
next.config.mjsexported an empty object with no HTTP security headers configured. Every response from AlgoBuddy was sent withoutX-Frame-Options,X-Content-Type-Options,Content-Security-Policy,Strict-Transport-Security,Referrer-Policy, orPermissions-Policy.This left the app exposed to four concrete attack vectors:
<iframe>on a malicious site and used to steal credentials.What changed and why
next.config.mjs— added aheaders()export that attaches six security headers to every route (source: "/(.*)"):X-Frame-OptionsDENYX-Content-Type-OptionsnosniffReferrer-Policystrict-origin-when-cross-originStrict-Transport-Securitymax-age=63072000; includeSubDomains; preloadPermissions-Policycamera=(), microphone=(), geolocation=()Content-Security-PolicyCSP sources audited from the live codebase:
script-src:googletagmanager.com(GA),challenges.cloudflare.com(Turnstile widget),va.vercel-scripts.com(Speed Insights),'unsafe-inline'for the two inline scripts inlayout.jsx(theme initialiser and GA config).style-src:fonts.googleapis.com(Google Fonts CSS import inglobals.css),'unsafe-inline'for Tailwind.font-src:fonts.gstatic.com(Google Fonts static files).connect-src:*.supabase.co(auth + DB),google-analytics.com,challenges.cloudflare.com,va.vercel-scripts.com.frame-src:challenges.cloudflare.com— Turnstile renders inside an iframe.frame-ancestors 'none': reinforcesX-Frame-Optionsfor CSP-aware browsers.Why this approach fixes the root cause
Using Next.js
headers()innext.config.mjsis the canonical way to set headers for all routes (including static, dynamic, and API routes). It runs at the edge before any page code executes, so no response can slip through without the headers.Steps to test
Run
npm run devand execute:All six headers must appear in the output.
Deploy to a Vercel preview branch and run:
Create an HTML file containing
<iframe src="https://algobuddy.in/login"></iframe>and open it in a browser — the frame must be blocked with a console error referencingX-Frame-Optionsorframe-ancestors.Verify the app functions normally end-to-end: login (Google OAuth + email), contact form, review form, visualizer, dashboard — no CSP console errors for any legitimate resource.
Edge cases covered
/(.*)— covers pages, API routes, and static assets.frame-ancestors 'none'duplicatesX-Frame-Optionsfor modern browsers that honour CSP over the legacy header.data:forimg-srcto support any base64-encoded images used in visualiser pages.unsafe-inlinefor scripts is scoped to the two identified inline scripts; no external inline attack surface is added.No regressions
npm run buildpasses without errors or warnings.curl -sI).Please review and merge this under GSSoC 2026.