@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 CHANGED
@@ -1,9 +1,9 @@
1
- # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.35.17/config/assets/logo.svg) Appsemble Node Utilities
1
+ # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.35.18/config/assets/logo.svg) Appsemble Node Utilities
2
2
 
3
3
  > NodeJS utilities used by Appsemble internally.
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/@appsemble/node-utils)](https://www.npmjs.com/package/@appsemble/node-utils)
6
- [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.35.17/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.35.17)
6
+ [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.35.18/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.35.18)
7
7
  [![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](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.17/LICENSE.md) ©
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.17",
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.17",
44
- "@appsemble/types": "0.35.17",
45
- "@appsemble/utils": "0.35.17",
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 [`'sha256-${hash}'`, `<script>${script}</script>`];
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();
package/server/types.d.ts CHANGED
@@ -204,6 +204,7 @@ export interface CreateSettingsParams {
204
204
  controllerDefinition?: ControllerDefinition;
205
205
  hostname: string;
206
206
  languages: string[];
207
+ nonce: string;
207
208
  }
208
209
  export interface GetCspParams {
209
210
  app: App;