Skip to content

Commit ebfde00

Browse files
Add missing nonce to script tag (#7672)
Follow-up to GHSA-68jh-rf6x-836f
1 parent 159d73c commit ebfde00

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

.changeset/rude-monkeys-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@apollo/server': patch
3+
---
4+
5+
Add missing `nonce` on `script` tag for non-embedded landing page

packages/server/src/__tests__/plugin/landingPage/plugin.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { ApolloServer, HeaderMap } from '@apollo/server';
2-
import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default';
2+
import {
3+
ApolloServerPluginLandingPageLocalDefault,
4+
ApolloServerPluginLandingPageProductionDefault,
5+
} from '@apollo/server/plugin/landingPage/default';
36
import { describe, expect, test } from '@jest/globals';
47
import assert from 'assert';
58
import { mockLogger } from '../../mockLogger';
@@ -61,4 +64,16 @@ describe('ApolloServerPluginLandingPageDefault', () => {
6164
);
6265
await server.stop();
6366
});
67+
68+
test(`nonce exists in non-embedded landing page`, async () => {
69+
const plugin = ApolloServerPluginLandingPageProductionDefault({
70+
embed: false,
71+
});
72+
73+
// @ts-ignore not passing things to `serverWillStart`
74+
const { renderLandingPage } = await plugin.serverWillStart?.({});
75+
const landingPageHtml = await (await renderLandingPage?.()).html();
76+
77+
expect(landingPageHtml).toMatch(/<script nonce=".*">window\.landingPage/);
78+
});
6479
});

packages/server/src/plugin/landingPage/default/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const getNonEmbeddedLandingPageHTML = (
7272
<h1>Welcome to Apollo Server</h1>
7373
<p>The full landing page cannot be loaded; it appears that you might be offline.</p>
7474
</div>
75-
<script>window.landingPage = ${encodedConfig};</script>
75+
<script nonce="${nonce}">window.landingPage = ${encodedConfig};</script>
7676
<script nonce="${nonce}" src="https://apollo-server-landing-page.cdn.apollographql.com/${encodeURIComponent(
7777
cdnVersion,
7878
)}/static/js/main.js?runtime=${apolloServerVersion}"></script>`;

0 commit comments

Comments
 (0)