-
-
Notifications
You must be signed in to change notification settings - Fork 3k
security(proxy-path): set Vary on public routes that echo x-proxy-path (cache poisoning) #8072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JohnMcLear
wants to merge
2
commits into
develop
Choose a base branch
from
security/proxy-path-vary-public-routes
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+115
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Cache-poisoning hardening for the `x-proxy-path` header on public routes. | ||
| * | ||
| * Etherpad echoes the (sanitised) `x-proxy-path` prefix into rendered URLs, | ||
| * social-preview metadata, PWA manifest links, and the legacy timeslider | ||
| * redirect on `/`, `/p/:pad`, and `/p/:pad/timeslider`. If a shared cache / | ||
| * reverse proxy in front of Etherpad stores these responses keyed on URL alone, | ||
| * a value injected by one client is served to every other client. These | ||
| * responses must therefore advertise `Vary: x-proxy-path` so a conforming cache | ||
| * keeps prefixed and non-prefixed variants separate. Reported by `meifukun`; | ||
| * companion to the already-fixed admin-route variant (GHSA-fjgc-3mj7-8rg8). | ||
| */ | ||
|
|
||
| const assert = require('assert').strict; | ||
| const common = require('../common'); | ||
| const padManager = require('../../../node/db/PadManager'); | ||
| import settings from '../../../node/utils/Settings'; | ||
|
|
||
| let agent: any; | ||
|
|
||
| const varyList = (res: any): string[] => | ||
| String(res.headers.vary || '').toLowerCase().split(',').map((s: string) => s.trim()); | ||
|
|
||
| const assertVariesOnProxyPath = (res: any, where: string) => { | ||
| if (!varyList(res).includes('x-proxy-path')) { | ||
| throw new Error( | ||
| `${where}: response must advertise "Vary: x-proxy-path" so a shared ` + | ||
| `cache cannot serve a poisoned proxy-path to another user ` + | ||
| `(got Vary: "${res.headers.vary || ''}")`); | ||
| } | ||
| }; | ||
|
|
||
| describe(__filename, function () { | ||
| this.timeout(30000); | ||
| const padId = 'ProxyPathVaryTest'; | ||
| let trustProxyBackup: any; | ||
|
|
||
| before(async function () { | ||
| agent = await common.init(); | ||
| await padManager.getPad(padId, 'test content'); | ||
| trustProxyBackup = settings.trustProxy; | ||
| }); | ||
|
|
||
| after(function () { | ||
| settings.trustProxy = trustProxyBackup; | ||
| }); | ||
|
|
||
| it('sets Vary: x-proxy-path on the home page', async function () { | ||
| const res = await agent.get('/').expect(200); | ||
| assertVariesOnProxyPath(res, 'GET /'); | ||
| }); | ||
|
|
||
| it('sets Vary: x-proxy-path on the pad page', async function () { | ||
| const res = await agent.get(`/p/${padId}`).expect(200); | ||
| assertVariesOnProxyPath(res, `GET /p/${padId}`); | ||
| }); | ||
|
|
||
| it('sets Vary: x-proxy-path on the timeslider embed page', async function () { | ||
| const res = await agent.get(`/p/${padId}/timeslider?embed=1`).expect(200); | ||
| assertVariesOnProxyPath(res, `GET /p/${padId}/timeslider?embed=1`); | ||
| }); | ||
|
|
||
| it('sets Vary: x-proxy-path on the legacy timeslider redirect', async function () { | ||
| const res = await agent.get(`/p/${padId}/timeslider`).expect(302); | ||
| assertVariesOnProxyPath(res, `GET /p/${padId}/timeslider (redirect)`); | ||
| }); | ||
|
|
||
| it('does NOT vary on the trust-gated headers when trustProxy is false', async function () { | ||
| // sanitizeProxyPath ignores x-forwarded-prefix / x-ingress-path unless | ||
| // trustProxy is enabled, so varying on them would only fragment caches. | ||
| settings.trustProxy = false; | ||
| const res = await agent.get('/').expect(200); | ||
| const vary = varyList(res); | ||
| assert.ok(vary.includes('x-proxy-path'), `expected x-proxy-path, got "${res.headers.vary}"`); | ||
| assert.ok(!vary.includes('x-forwarded-prefix'), | ||
| `must not vary on x-forwarded-prefix when trustProxy=false (got "${res.headers.vary}")`); | ||
| assert.ok(!vary.includes('x-ingress-path'), | ||
| `must not vary on x-ingress-path when trustProxy=false (got "${res.headers.vary}")`); | ||
| }); | ||
|
|
||
| it('varies on all proxy-path headers when trustProxy is true', async function () { | ||
| settings.trustProxy = true; | ||
| const res = await agent.get('/').expect(200); | ||
| const vary = varyList(res); | ||
| assert.ok(vary.includes('x-proxy-path'), `expected x-proxy-path, got "${res.headers.vary}"`); | ||
| assert.ok(vary.includes('x-forwarded-prefix'), | ||
| `expected x-forwarded-prefix when trustProxy=true (got "${res.headers.vary}")`); | ||
| assert.ok(vary.includes('x-ingress-path'), | ||
| `expected x-ingress-path when trustProxy=true (got "${res.headers.vary}")`); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.