Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions Application-Code/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
FROM node:14
WORKDIR /usr/src/app
# ==========================================================
# Stage 1: Build
# Use Node.js 20 (Alpine) to install dependencies and build the app
# ==========================================================
FROM node:20-alpine AS build

# Set the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json first (for better layer caching)
COPY package*.json ./
RUN npm install

# Install dependencies using the lockfile (faster, reproducible builds)
RUN npm ci

# Copy the rest of the application code to the container
COPY . .
CMD [ "npm", "start" ]

# Build the production-ready static files
RUN npm run build


# ==========================================================
# Stage 2: Production
# Serve the built static files using a lightweight Nginx image
# ==========================================================
FROM nginx:1.27-alpine

# Copy built static files from the build stage into Nginx's serving directory
COPY --from=build /app/build /usr/share/nginx/html

# Expose the port Nginx listens on
EXPOSE 80

# Run Nginx in the foreground (required for Docker containers)
CMD ["nginx", "-g", "daemon off;"]
Comment on lines +27 to +36

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Run Nginx as a non-root user in the runtime stage.

Line 27+ currently uses an image/config that runs as root by default, and there is no USER override. This weakens container isolation and matches the DS-0002 finding.

Suggested hardening patch
-FROM nginx:1.27-alpine
+FROM nginxinc/nginx-unprivileged:1.27-alpine

 # Copy built static files from the build stage into Nginx's serving directory
 COPY --from=build /app/build /usr/share/nginx/html

-# Expose the port Nginx listens on
-EXPOSE 80
+# Unprivileged nginx listens on 8080 by default
+EXPOSE 8080

 # Run Nginx in the foreground (required for Docker containers)
 CMD ["nginx", "-g", "daemon off;"]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Application-Code/frontend/Dockerfile` around lines 27 - 36, The runtime stage
Dockerfile is running Nginx as the root user by default, creating a security
vulnerability. Add a USER directive in the Dockerfile after the COPY instruction
and before the CMD instruction to run Nginx as a non-root user. Use a
non-privileged user that exists in the nginx:1.27-alpine image, such as the
nginx user, to ensure the container runs with reduced privileges and improved
isolation.

Source: Linters/SAST tools