fix(core): SHA256 hash for JS scripts CSP on Windows - #14265
Conversation
we hash JS scripts as SHA256 for the Content-Security-Policy (CSP) header. The isolation pattern is broken on Windows due to the hash including carriage return characters, which are not processed when the webview checks the script hash to see if the CSP allows the script.
Package Changes Through b5ae335There are 10 changes which include @tauri-apps/api with minor, tauri-cli with minor, tauri-utils with minor, tauri-runtime-wry with minor, tauri-runtime with minor, tauri with minor, tauri-bundler with minor, @tauri-apps/cli with minor, tauri-codegen with patch, tauri-macros with patch Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
|
|
||
| /// Normalize line endings in script content to match what the browser uses for CSP hashing. | ||
| /// | ||
| /// According to the HTML spec, browsers normalize: |
There was a problem hiding this comment.
Is there a source that we could put a link here?
There was a problem hiding this comment.
i tried to find one but couldn't 😂 maybe this was AI hallucination
There was a problem hiding this comment.
I think it's better be clear about this, I'm afraid to introduce regressions on other platforms if this is not true for them (although rare, they could also have files ending in CRLF), and if that's a behavior we shouldn't rely on, it could break in the future
There was a problem hiding this comment.
Just some information: I was wondering how this worked for the regular inline script in user provided HTML, and from testing, kuchiki::parse_html seems to convert \r\n to \n which seemed to make it work, but for the isolation case, we inserted the js file in inline_isolation directly to the document tree, so it preserved the CRLF
tauri/crates/tauri-codegen/src/context.rs
Lines 47 to 66 in c57e098
There was a problem hiding this comment.
ohh i was wondering the same - good to know
There was a problem hiding this comment.
oh so maybe we should fix inline_isolation instead? :|
There was a problem hiding this comment.
No idea, I feel like this is pure magic now, I have no idea in which step, the CRLF became LF (using save as in the webview2 devtools on the index.html response gave me LF while we surely returned one ending in CRLF, don't know if it's the devtools or it's something else) (don't know if the CSP is calculated from something like innerText or from the HTML file directly either), I would say switching to use nouce in inline_isolation is a more realistic fix 😂
|
I don't know how you even found this out, good job! 😂 |
we hash JS scripts as SHA256 for the Content-Security-Policy (CSP) header. The isolation pattern is broken on Windows due to the hash including carriage return characters, which are not processed when the webview checks the script hash to see if the CSP allows the script.