Skip to content

Commit

Permalink
Add missing nonce to script tag (#7672)
Browse files Browse the repository at this point in the history
Follow-up to
GHSA-68jh-rf6x-836f
  • Loading branch information
trevor-scheer committed Aug 4, 2023
1 parent 159d73c commit ebfde00
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-monkeys-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@apollo/server': patch
---

Add missing `nonce` on `script` tag for non-embedded landing page
17 changes: 16 additions & 1 deletion packages/server/src/__tests__/plugin/landingPage/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ApolloServer, HeaderMap } from '@apollo/server';
import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default';
import {
ApolloServerPluginLandingPageLocalDefault,
ApolloServerPluginLandingPageProductionDefault,
} from '@apollo/server/plugin/landingPage/default';
import { describe, expect, test } from '@jest/globals';
import assert from 'assert';
import { mockLogger } from '../../mockLogger';
Expand Down Expand Up @@ -61,4 +64,16 @@ describe('ApolloServerPluginLandingPageDefault', () => {
);
await server.stop();
});

test(`nonce exists in non-embedded landing page`, async () => {
const plugin = ApolloServerPluginLandingPageProductionDefault({
embed: false,
});

// @ts-ignore not passing things to `serverWillStart`
const { renderLandingPage } = await plugin.serverWillStart?.({});
const landingPageHtml = await (await renderLandingPage?.()).html();

expect(landingPageHtml).toMatch(/<script nonce=".*">window\.landingPage/);
});
});
2 changes: 1 addition & 1 deletion packages/server/src/plugin/landingPage/default/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const getNonEmbeddedLandingPageHTML = (
<h1>Welcome to Apollo Server</h1>
<p>The full landing page cannot be loaded; it appears that you might be offline.</p>
</div>
<script>window.landingPage = ${encodedConfig};</script>
<script nonce="${nonce}">window.landingPage = ${encodedConfig};</script>
<script nonce="${nonce}" src="https://apollo-server-landing-page.cdn.apollographql.com/${encodeURIComponent(
cdnVersion,
)}/static/js/main.js?runtime=${apolloServerVersion}"></script>`;
Expand Down

0 comments on commit ebfde00

Please sign in to comment.