# GHSA-68jh-rf6x-836f: @apollo/server vulnerable to unsafe application of Content Security Policy via reused nonces

> Apollo Server's landing pages reused CSP nonces, failing to prevent XSS if other vectors exist, requiring an upgrade to fix.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 16 Jun 2023

## What is GHSA-68jh-rf6x-836f?

GHSA-68jh-rf6x-836f is a vulnerability in @apollo/server, published on 16 Jun 2023. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

### Context
Content Security Policies (CSP) are a defense-in-depth strategy against XSS attacks. Improper application of CSP isn't itself a vulnerability, but it does fail to prevent XSS in the event that there is a viable attack vector for an XSS attack.

### Impact
There aren't any XSS attack vectors via the Apollo Server landing pages _known to Apollo_, so to our knowledge there is no impact. However, if there are existing XSS vectors that haven't been reported and patched, then all users of Apollo Server's landing pages have a vulnerability which won't be prevented by the current CSP implemented by the landing pages.

Prior to version 4.7.1, there was no CSP implemented at all. However, the initial CSP implementation (4.7.1+) reused nonces. While this sufficiently resolved the issue w.r.t. scripts not running in Safari, it did not implement CSP in a safe or conventional way.

### Patches
The issue is patched in the latest version of Apollo Server, v4.7.4. The changes can be reviewed in [the merge commit](https://github.com/apollographql/apollo-server/commit/0adaf80d1ee51d8c7e5fd863c04478536d15eb8c).

### Workarounds
The landing page can be disabled completely until the patch can be upgraded to.
https://www.apollographql.com/docs/apollo-server/api/plugin/landing-pages/#disabling-the-landing-page

### References
https://content-security-policy.com/nonce/

## Which versions are affected by GHSA-68jh-rf6x-836f?

2 open source packages ship an affected version, including @apollo/server.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `@apollo/server` | npm | From 4.7.1 | 4.7.4 |
| `@apollo/server` | npm | From 4.7.1 | 4.7.4 |

## How do I fix GHSA-68jh-rf6x-836f?

Upgrade @apollo/server to 4.7.4 or later.

## Is GHSA-68jh-rf6x-836f being exploited?

There is no known exploitation of GHSA-68jh-rf6x-836f in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-68jh-rf6x-836f and fix it if it is affected.

What it is: GHSA-68jh-rf6x-836f is a vulnerability in @apollo/server, published on 16 Jun 2023. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of GHSA-68jh-rf6x-836f in the wild and no public exploit code.

Affected packages and fixed versions:
- @apollo/server (npm): affected from 4.7.1; fixed in 4.7.4
- @apollo/server (npm): affected from 4.7.1; fixed in 4.7.4

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-68jh-rf6x-836f/ (Markdown: https://insights.sbomify.com/GHSA-68jh-rf6x-836f/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-68jh-rf6x-836f

---
From sbomify Insights: https://insights.sbomify.com/GHSA-68jh-rf6x-836f/
Summaries are generated and may contain mistakes; the official description above is the record.
