Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content-Security-Policy: add strict csp headers and use a nonce #97

Merged
merged 20 commits into from
Oct 9, 2024

Conversation

abhiramtilakiiit
Copy link
Contributor

@abhiramtilakiiit abhiramtilakiiit commented Sep 11, 2024

Need for Changes

  • The latest google lighthouse report has shown how we allow unsafe-inline styles and
    basically have no CSP in place.

According to nextjs docs it is recommended to add these headers to the middleware and wherever
needed (when external scripts or inline scripts are being called), add the nonce instead
to uniquely generate a nonce everytime the page loads.

  • Since we are using MUI, their docs, instruct
    addind nonce to the ThemeRegistry using aa cache provider. (Update: We are having to use unsafe-inline because some MUI components use inline styles (mui github: issues/19938), we will remove this if it gets fixed upstream sometime).

Changes

  • I have added some strict headers and made some changes so the redirects also return these headers.
  • I have included the nonce in the ThemeRegistry style tag, and the subsequent CacheProvider to cache it out.
  • I have added *.iiit.ac.in, as a white list to <iframe> as long as it is being displayed in the iiit website.

Todo

  • There are some instances where CSP errors out, please pay close attention to the browser console.

@bhavberi bhavberi added the security can related to authorization of pages and content label Oct 4, 2024
Copy link
Member

@Dileepadari Dileepadari left a comment

Choose a reason for hiding this comment

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

Looks good, testing with different components done, can be merged.

@Dileepadari Dileepadari merged commit 09dfad0 into master Oct 9, 2024
2 checks passed
@Dileepadari Dileepadari deleted the scp branch October 9, 2024 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security can related to authorization of pages and content
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants