Skip to content

Fix security issue: Serve static files from public directory#16

Merged
Ashrithhn merged 1 commit into
Ashrithhn:mainfrom
Adithyakp86:main
May 1, 2026
Merged

Fix security issue: Serve static files from public directory#16
Ashrithhn merged 1 commit into
Ashrithhn:mainfrom
Adithyakp86:main

Conversation

@Adithyakp86

Copy link
Copy Markdown

Description

This Pull Request addresses a security vulnerability where the express.static middleware was configured to serve files directly from the root directory (__dirname). This configuration inadvertently exposed sensitive server-side files (like server.js, package.json) and potentially private user data (like contacts.json) to the public via direct URL access.

Changes Made

  • Created a dedicated public folder in the project root.
  • Moved all public-facing static frontend assets (styles.css, script.js, favicon.ico, and robots.txt) into the new public directory.
  • Updated the Express static middleware configuration in server.js to strictly serve files from the public directory instead of the root.

Steps to Test

  1. Pull down this branch and start the server locally (npm start or node server.js).
  2. Navigate to the application and verify that all static assets (styles, scripts, etc.) load correctly.
  3. Attempt to access http://localhost:3000/server.js or http://localhost:3000/package.json in your browser.
  4. Confirm that the server now returns a 404 Not Found error for these files instead of exposing their contents.

@Ashrithhn
Ashrithhn merged commit 8a2d224 into Ashrithhn:main May 1, 2026
2 of 3 checks passed
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.

2 participants