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

Unable to obtain SRI hash for local resource #80

Open
mvantschip opened this issue May 3, 2024 · 0 comments
Open

Unable to obtain SRI hash for local resource #80

mvantschip opened this issue May 3, 2024 · 0 comments

Comments

@mvantschip
Copy link

mvantschip commented May 3, 2024

I am rending a server in hybrid mode and setting the Content-Security-Policy in astro.config.mjs as follows:

sri: {
      hashesModule: sriHashesModule,
      enableMiddleware: true
    },
    securityHeaders: {
      contentSecurityPolicy: {
        cspDirectives: {
          'default-src': "'self'",
          'font-src': "'self'",
          'img-src': "'self'",
          'form-action': "'self'",
          'connect-src': "'self'",
          'frame-ancestors': "'none'",
        }
      }
    }

When working in development, I get constant console errors. astro dev shows "Unable to obtain SRI hash for local resource", while my web console shows errors alike "The page’s settings blocked an inline style (style-src-elem) from being applied because it violates the following directive: “style-src 'self' 'hashes' 'hashes' 'hashes'". In addition, I get errors when dynamically loading certain content...

From all these errors, it seems that there is a problem with the SRI hashes, but I am not sure what I am doing wrong.

I setup my sriHashesModule as in the docs:

const rootDir = new URL('.', import.meta.url).pathname;
const sriHashesModule = resolve(rootDir, 'src', 'generated', 'sri.mjs');

Am I doing something wrong in setting this up?

Many thanks for your work and support!

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

No branches or pull requests

1 participant