@appsemble/node-utils 0.35.17 → 0.35.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +4 -4
- package/render.d.ts +2 -1
- package/render.js +6 -2
- package/server/routes/appRouter/indexHandler.js +2 -1
- package/server/types.d.ts +1 -0
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#  Appsemble Node Utilities
|
|
2
2
|
|
|
3
3
|
> NodeJS utilities used by Appsemble internally.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@appsemble/node-utils)
|
|
6
|
-
[](https://gitlab.com/appsemble/appsemble/-/releases/0.35.18)
|
|
7
7
|
[](https://prettier.io)
|
|
8
8
|
|
|
9
9
|
## Table of Contents
|
|
@@ -26,5 +26,5 @@ compatibility is not guaranteed.
|
|
|
26
26
|
|
|
27
27
|
## License
|
|
28
28
|
|
|
29
|
-
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.35.
|
|
29
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.35.18/LICENSE.md) ©
|
|
30
30
|
[Appsemble](https://appsemble.com)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/node-utils",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.18",
|
|
4
4
|
"description": "NodeJS utilities used by Appsemble internally.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"test": "vitest"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@appsemble/lang-sdk": "0.35.
|
|
44
|
-
"@appsemble/types": "0.35.
|
|
45
|
-
"@appsemble/utils": "0.35.
|
|
43
|
+
"@appsemble/lang-sdk": "0.35.18",
|
|
44
|
+
"@appsemble/types": "0.35.18",
|
|
45
|
+
"@appsemble/utils": "0.35.18",
|
|
46
46
|
"@formatjs/fast-memoize": "^2.0.0",
|
|
47
47
|
"@fortawesome/fontawesome-free": "^6.0.0",
|
|
48
48
|
"@kubernetes/client-node": "^0.22.2",
|
package/render.d.ts
CHANGED
|
@@ -4,11 +4,12 @@ import { type Context } from 'koa';
|
|
|
4
4
|
* Render settings as an HTML script tag.
|
|
5
5
|
*
|
|
6
6
|
* @param settings The settings to render. This must be a JSON serializable object.
|
|
7
|
+
* @param nonce The settings nonce.
|
|
7
8
|
* @param statements Custom JavaScript statements to append.
|
|
8
9
|
* @returns A tuple of the digest and the HTML script tag. The digest should be added to the CSP
|
|
9
10
|
* `script-src`.
|
|
10
11
|
*/
|
|
11
|
-
export declare function createSettings(settings: unknown, statements?: string[]): [digest: string, script: string];
|
|
12
|
+
export declare function createSettings(settings: unknown, nonce?: string, statements?: string[]): [digest: string, script: string];
|
|
12
13
|
export declare function render(ctx: Context, filename: string, data: Record<string, unknown>): Promise<void>;
|
|
13
14
|
/**
|
|
14
15
|
* Convert a CSP key / values pair object into a real content security policy string.
|
package/render.js
CHANGED
|
@@ -6,14 +6,18 @@ import mustache from 'mustache';
|
|
|
6
6
|
* Render settings as an HTML script tag.
|
|
7
7
|
*
|
|
8
8
|
* @param settings The settings to render. This must be a JSON serializable object.
|
|
9
|
+
* @param nonce The settings nonce.
|
|
9
10
|
* @param statements Custom JavaScript statements to append.
|
|
10
11
|
* @returns A tuple of the digest and the HTML script tag. The digest should be added to the CSP
|
|
11
12
|
* `script-src`.
|
|
12
13
|
*/
|
|
13
|
-
export function createSettings(settings, statements = []) {
|
|
14
|
+
export function createSettings(settings, nonce, statements = []) {
|
|
14
15
|
const script = [`window.settings=${JSON.stringify(settings)}`, ...statements].join(';');
|
|
15
16
|
const hash = createHash('sha256').update(script, 'utf8').digest('base64');
|
|
16
|
-
return [
|
|
17
|
+
return [
|
|
18
|
+
`'sha256-${hash}'`,
|
|
19
|
+
nonce ? `<script nonce="${nonce}">${script}</script>` : `<script>${script}</script>`,
|
|
20
|
+
];
|
|
17
21
|
}
|
|
18
22
|
export async function render(ctx, filename, data) {
|
|
19
23
|
if (process.env.NODE_ENV === 'test') {
|
|
@@ -39,6 +39,7 @@ export function createIndexHandler({ createSettings, getApp, getAppDetails, getA
|
|
|
39
39
|
...new Set([...appMessages.map(({ language }) => language), defaultLanguage]),
|
|
40
40
|
].sort();
|
|
41
41
|
const identifiableBlocks = getAppBlocks(app.definition);
|
|
42
|
+
const nonce = randomBytes(16).toString('base64');
|
|
42
43
|
const [settingsHash, settings] = await createSettings({
|
|
43
44
|
context: ctx,
|
|
44
45
|
app,
|
|
@@ -46,8 +47,8 @@ export function createIndexHandler({ createSettings, getApp, getAppDetails, getA
|
|
|
46
47
|
hostname,
|
|
47
48
|
identifiableBlocks,
|
|
48
49
|
languages,
|
|
50
|
+
nonce,
|
|
49
51
|
});
|
|
50
|
-
const nonce = randomBytes(16).toString('base64');
|
|
51
52
|
const csp = getCsp({ app, settingsHash, hostname, host, nonce });
|
|
52
53
|
ctx.set('Content-Security-Policy', makeCSP(csp));
|
|
53
54
|
const updated = app.$updated ? new Date(app.$updated) : new Date();
|