You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Static adapter with sveltekit.
My adapter configuration is as follows:
**import adapter from '@sveltejs/adapter-static';
export default {
kit: {
adapter: adapter({
// default options are shown. On some platforms
// these options are set automatically — see below
pages: 'build',
assets: 'build',
fallback: undefined,
precompress: false,
strict: true
}), csp:{
mode:"hash",
directives: {
'script-src': ['self']
},
}
}
};**
This will render the pages after building .
for example i took a simple code of counter increment and decrement in svelte. The code:
in +page.svelte of routes directory.
**<script>
let count=0
</script>
count is {count}
count++}>increment
count--}>decrement**
After running npm run build, it produced the index.html of in build for this route.
The code of the html:
As you can see a hash is generated and added to content security policy in the html.
But when i deploy this to IIS with the web.config:
**
<system.webServer>
<!-- Add the X-Content-Type-Options header with value 'nosniff' -->
<add name="X-Content-Type-Options" value="nosniff" />
<!-- Add the Content-Security-Policy header with an updated CSP policy -->
<add name="Content-Security-Policy" value="
script-src 'self'
" />
</customHeaders>
</httpProtocol>
<!-- Other IIS configurations may be present here -->
</system.webServer>
**
The site isn't working anymore.
Console gave the error:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-vcM02ybV5AL1ye50l3REFlx7X0T57ATTV3r3Dywhv58='), or a nonce ('nonce-...') is required to enable inline execution.
And this executes as expected when "script-src 'self' " is removed from web.config file.
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-vcM02ybV5AL1ye50l3REFlx7X0T57ATTV3r3Dywhv58='), or a nonce ('nonce-...') is required to enable inline execution.
The problem is orginally in my other project. but i have reproduced it in a simple project in similar situation.
And this is first time iam raising a github issue.So, let me know if i have missed anything.
The text was updated successfully, but these errors were encountered:
chirudeepnamini
changed the title
Prerendered pages with static adapter not working unless "unsafe-inline" is being used in content security policy when deployed to IIS
Prerendered pages with static adapter not working unless "unsafe-inline" is used in content security policy when deployed to IIS
Nov 10, 2023
Browsers don't allow "unsafe-inline" for browser extensions. But adapter-static even uses inline scripts when you disable prerendering. I'm a bit clueless on how to use SvelteKit for web extensions because of this.
Describe the bug
I am using Static adapter with sveltekit.
My adapter configuration is as follows:
**import adapter from '@sveltejs/adapter-static';
export default {
kit: {
adapter: adapter({
// default options are shown. On some platforms
// these options are set automatically — see below
pages: 'build',
assets: 'build',
fallback: undefined,
precompress: false,
strict: true
}), csp:{
mode:"hash",
directives: {
'script-src': ['self']
},
};**
This will render the pages after building .
for example i took a simple code of counter increment and decrement in svelte. The code:
in +page.svelte of routes directory.
**<script>
let count=0
</script>
count is {count}
count++}>increment count--}>decrement**After running npm run build, it produced the index.html of in build for this route.
The code of the html:
**
count is 0
increment decrementAs you can see a hash is generated and added to content security policy in the html.
But when i deploy this to IIS with the web.config:
**
<system.webServer>
</system.webServer>
**
The site isn't working anymore.
Console gave the error:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-vcM02ybV5AL1ye50l3REFlx7X0T57ATTV3r3Dywhv58='), or a nonce ('nonce-...') is required to enable inline execution.
And this executes as expected when "script-src 'self' " is removed from web.config file.
Reproduction
I have uploaded the code(including the build folder with web.config) for reproduction here:
https://github.com/chirudeepnamini/sveltekit-issue
Logs
System Info
Severity
blocking all usage of SvelteKit
Additional Information
The problem is orginally in my other project. but i have reproduced it in a simple project in similar situation.
And this is first time iam raising a github issue.So, let me know if i have missed anything.
The text was updated successfully, but these errors were encountered: