Skip to content

Commit

Permalink
Merge pull request #867 from makerdao/middleware-headers
Browse files Browse the repository at this point in the history
Modify middleware to not return request headers in response object
  • Loading branch information
b-pmcg authored Apr 17, 2024
2 parents 192e875 + 3cdd2d1 commit 8fd812a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ export async function middleware(request: NextRequest) {
img-src 'self' https: data:;
`;

// Replace newline characters and spaces
const contentSecurityPolicyHeaderValue = cspHeader.replace(/\s{2,}/g, ' ').trim();

const requestHeaders = new Headers(request.headers);
requestHeaders.set('x-nonce', nonce);
requestHeaders.set(
'Content-Security-Policy',
// Replace newline characters and spaces
cspHeader.replace(/\s{2,}/g, ' ').trim()
);

return NextResponse.next({
headers: requestHeaders,
requestHeaders.set('Content-Security-Policy', contentSecurityPolicyHeaderValue);

const response = NextResponse.next({
request: {
headers: requestHeaders
}
});

response.headers.set('Content-Security-Policy', contentSecurityPolicyHeaderValue);

return response;
}

0 comments on commit 8fd812a

Please sign in to comment.