Skip to content

refactor: remove static file caching from nginx configuration and enh… - #17

Merged
GamingOP69 merged 1 commit into
GamingOP69:mainfrom
Sarika-Kafle:main
Jun 5, 2026
Merged

GamingOP69 merged 1 commit into
GamingOP69:mainfrom
Sarika-Kafle:main

Conversation

@Sarika-Kafle

Copy link
Copy Markdown
Contributor

…ance security headers in next.config

Copilot AI review requested due to automatic review settings June 5, 2026 16:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates HTTP header configuration to centralize security headers in Next.js and adjust caching behavior, while removing Nginx static-asset caching rules.

Changes:

  • Centralized security headers in next.config.mjs and added a default Cache-Control: no-store header for most routes.
  • Scoped Next.js headers to exclude /_next/static and /_next/image.
  • Removed Nginx location blocks that set long-lived caching headers for static assets.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
next.config.mjs Adds shared security headers + applies no-store caching to most routes; changes header scope pattern.
deploy/nginx/nginx.conf.template Removes static asset caching location block.
deploy/nginx/nginx.conf Removes static asset caching location block (and its comment).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread next.config.mjs
Comment on lines +33 to +37
source: '/((?!_next/static|_next/image).*)',
headers: [
...dynamicHeaders,
{ key: 'Content-Security-Policy', value: csp }
]
Comment thread next.config.mjs
Comment on lines +10 to +13
const dynamicHeaders = [
...securityHeaders,
{ key: 'Cache-Control', value: 'no-store, max-age=0, must-revalidate' }
];
Comment thread next.config.mjs
Comment on lines +2 to +8
const securityHeaders = [
{ key: 'X-Frame-Options', value: 'DENY' },
{ key: 'X-Content-Type-Options', value: 'nosniff' },
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
{ key: 'Permissions-Policy', value: 'geolocation=(), microphone=(), camera=(), payment=()' },
{ key: 'X-XSS-Protection', value: '1; mode=block' }
];
Comment thread deploy/nginx/nginx.conf
Comment on lines 35 to 38
proxy_set_header Connection "";
proxy_pass http://app:3000;
}

# Static file caching
location ~* \.(?:css|js|jpg|jpeg|gif|png|svg|ico|woff2?)$ {
expires 30d;
add_header Cache-Control "public, max-age=2592000, immutable";
proxy_pass http://app:3000;
}
}
Comment on lines 35 to 38
proxy_set_header Connection "";
proxy_pass http://app:3000;
}

location ~* \.(?:css|js|jpg|jpeg|gif|png|svg|ico|woff2?)$ {
expires 30d;
add_header Cache-Control "public, max-age=2592000, immutable";
proxy_pass http://app:3000;
}
}

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request removes static file caching from the Nginx configuration and refactors security and dynamic headers in next.config.mjs. Key feedback includes restoring the production-conditional HSTS (Strict-Transport-Security) header that was removed, updating the route matching pattern in next.config.mjs to prevent disabling cache for public static assets, and ensuring that security headers are not duplicated between Next.js and Nginx configurations.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread next.config.mjs
Comment on lines +2 to +8
const securityHeaders = [
{ key: 'X-Frame-Options', value: 'DENY' },
{ key: 'X-Content-Type-Options', value: 'nosniff' },
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
{ key: 'Permissions-Policy', value: 'geolocation=(), microphone=(), camera=(), payment=()' },
{ key: 'X-XSS-Protection', value: '1; mode=block' }
];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-high high

Defining these security headers in next.config.mjs while they are also defined via add_header directives in deploy/nginx/nginx.conf (and deploy/nginx/nginx.conf.template) will result in duplicate headers being sent in the HTTP response. Duplicate headers (like X-Frame-Options or Referrer-Policy) can cause browsers to ignore the policies or behave unexpectedly. To resolve this, please remove the duplicate add_header directives from your Nginx configuration files so that Next.js remains the single source of truth for these headers.

Comment thread next.config.mjs
Comment on lines 31 to 39
return [
{
source: '/(.*)',
headers
source: '/((?!_next/static|_next/image).*)',
headers: [
...dynamicHeaders,
{ key: 'Content-Security-Policy', value: csp }
]
}
];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-high high

The HSTS (Strict-Transport-Security) header logic that was previously applied only in production has been completely removed. If this application is deployed directly or in environments where Nginx is not sitting in front of it (e.g., direct PaaS or serverless deployments), it will lack HSTS protection. It is highly recommended to restore the production-conditional HSTS header in next.config.mjs.

    const headers = [
      ...dynamicHeaders,
      { key: 'Content-Security-Policy', value: csp }
    ];

    if (process.env.NODE_ENV === 'production') {
      headers.push({ key: 'Strict-Transport-Security', value: 'max-age=63072000; includeSubDomains; preload' });
    }

    return [
      {
        source: '/((?!_next/static|_next/image).*)',
        headers
      }
    ];

Comment thread next.config.mjs
{
source: '/(.*)',
headers
source: '/((?!_next/static|_next/image).*)',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The negative lookahead pattern /((?!_next/static|_next/image).*) matches all routes except _next/static and _next/image. This means that any static assets served from the public directory (such as /favicon.ico, /robots.txt, or other custom images/fonts) will match this route and receive the Cache-Control: no-store, max-age=0, must-revalidate header. This disables caching for all public assets, causing a performance regression. Consider updating the pattern to also exclude common static file extensions or specific public files.

Suggested change
source: '/((?!_next/static|_next/image).*)',
source: '/((?!_next/static|_next/image|favicon.ico|robots.txt|.*\\.(?:svg|png|jpg|jpeg|gif|ico|webp|woff2?)).*)',

@GamingOP69
GamingOP69 merged commit 63521bd into GamingOP69:main Jun 5, 2026
1 check 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.

3 participants