I’m trying to set up a CSP as per the guidelines here: Security | Meteor Guide
The (main) issue I am having is in this part of the code:
// Prepare runtime config for generating the sha256 hash
// It is important, that the hash meets exactly the hash of the
// script in the client bundle.
// Otherwise the app would not be able to start, since the runtimeConfigScript
// is rejected __meteor_runtime_config__ is not available, causing
// a cascade of follow-up errors.
const runtimeConfig = Object.assign(__meteor_runtime_config__, Autoupdate, {
// the following lines may depend on, whether you called Accounts.config
// and whether your Meteor app is a "newer" version
accountsConfigCalled: true,
isModern: true,
});
/// ...
const runtimeConfigScript = `__meteor_runtime_config__ = JSON.parse(decodeURIComponent("${encodeURIComponent(
JSON.stringify(runtimeConfig)
)}"))`;
const runtimeConfigHash = crypto.createHash(`sha256`).update(runtimeConfigScript).digest(`base64`);
The runtimeConfigHash generated for the CSP does not match what’s being built at runtime. After parsing out and analysing the differences, it seems the generated code has some values that runtimeConfigHash
does not have.
Specifically as per below - extra lines in code labelled with <---- THIS LINE does not exist in runtimeConfigHash :
{
"meteorRelease": "METEOR@2.15",
"gitCommitHash": "b74823974210b87beb4d832ee5cf4a404c8c39f0",
"meteorEnv": {
"NODE_ENV": "development",
"TEST_METADATA": "{}"
},
"PUBLIC_SETTINGS": {
"foo": "bar"
},
"ROOT_URL": "http://localhost:3000/",
"ROOT_URL_PATH_PREFIX": "",
"reactFastRefreshEnabled": true,
"autoupdate": {
"versions": {
"web.browser": {
"version": "9f4f2565d3907c66bce0ba12b13e4b6ad606a786",
"versionRefreshable": "b94e9d10c1d9bdb6b3ecd2e68671e5ca8697db1b",
"versionNonRefreshable": "ac6592debd66ac85a7003e5af726cfb47e315e44",
"versionReplaceable": "85c79f1a9fd0f202b134a91b37e15fa4c5a69cf2",
"versionHmr": 1718084148520. <---- THIS LINE does not exist in runtimeConfigHash, changes each build
},
"versionHmr": 1718084148520. <---- THIS LINE does not exist in runtimeConfigHash, same each build
},
"autoupdateVersion": null,
"autoupdateVersionRefreshable": null,
"autoupdateVersionCordova": null,
"appId": "1t230wbbhj2a9nz92h"
},
"appId": "1t230wbbhj2a9nz92h",
"versions": {
"web.browser": {
"version": "9f4f2565d3907c66bce0ba12b13e4b6ad606a786",
"versionRefreshable": "b94e9d10c1d9bdb6b3ecd2e68671e5ca8697db1b",
"versionNonRefreshable": "ac6592debd66ac85a7003e5af726cfb47e315e44",
"versionReplaceable": "85c79f1a9fd0f202b134a91b37e15fa4c5a69cf2",
"versionHmr": 1718084148520 <---- THIS LINE does not exist in runtimeConfigHash, changes each build
},
"versionHmr": 1718084148520 <---- THIS LINE does not exist in runtimeConfigHash, same each build
},
"autoupdateVersion": null,
"autoupdateVersionRefreshable": null,
"autoupdateVersionCordova": null,
"accountsConfigCalled": true,
"isModern": true,
"kadira": { <---- THIS LINE does not exist in runtimeConfigHash
"appId": "IIvPOSCkmSoLB2iZ", <---- THIS LINE does not exist in runtimeConfigHash
"endpoint": "https://engine.montiapm.com", <---- THIS LINE does not exist in runtimeConfigHash
"clientEngineSyncDelay": 10000, <---- THIS LINE does not exist in runtimeConfigHash
"recordIPAddress": "full", <---- THIS LINE does not exist in runtimeConfigHash
"disableClientErrorTracking": false, <---- THIS LINE does not exist in runtimeConfigHash
"enableErrorTracking": true <---- THIS LINE does not exist in runtimeConfigHash
}
}
Questions:
- I imagine I can hard-code the Kadira/Monti-APM values as they don’t seem dynamic but what is the versionHmr value and how can I accurately generate that for the CSP?
- Do the docs regarding this need updating or have I made a mistake in the implementation?
Thanks in advance!