Skip to content

Commit

Permalink
Post fix for incorrect type (#1827)
Browse files Browse the repository at this point in the history
* We already have the hex string and default for Buffer is `utf`... so coerce it to `hex` which makes it "binary"
* Open up script sending to this methodology. Minification output support may come later but if one relies on the hash and something changes in the backend it can easily foo script installation. Will have to ponder some more.

Post #1826

Auto-merge
  • Loading branch information
Martii committed Jul 21, 2021
1 parent dfddc4c commit 715c10b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ exports.sendScript = function (aReq, aRes, aNext) {
}

hashSRI = aScript.hash
? 'sha512-' + Buffer.from(aScript.hash).toString('base64')
? 'sha512-' + Buffer.from(aScript.hash, 'hex').toString('base64')
: 'undefined';

// HTTP/1.1 Caching
Expand Down Expand Up @@ -687,6 +687,7 @@ exports.sendScript = function (aReq, aRes, aNext) {
source = chunks.join(''); // NOTE: Watchpoint

// Send the script
aRes.set('Access-Control-Allow-Origin', '*');
aRes.set('Content-Type', 'text/javascript; charset=UTF-8');
aStream.setEncoding('utf8');

Expand Down
2 changes: 1 addition & 1 deletion libs/modelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ var parseScript = function (aScript) {
if (script.hash) {
// NOTE: May be absent in dev DB but should not be in pro DB
script.hashShort = script.hash.substr(0, 7);
script.hashSRI = 'sha512-' + Buffer.from(script.hash).toString('base64');
script.hashSRI = 'sha512-' + Buffer.from(script.hash, 'hex').toString('base64');
}

if (script.created && script.updated && script.created.toString() !== script.updated.toString()) {
Expand Down

0 comments on commit 715c10b

Please sign in to comment.