Skip to content

Commit d9b6f88

Browse files
committed
fix: set Vary: X-Forwarded-Prefix on the injected index.html
The index.html body varies by the X-Forwarded-Prefix header (it drives the injected <base href> and window.__BASE_PATH__). Without a matching Vary header, a CDN or intermediate proxy could cache one prefix's response and serve it to users on a different prefix — a cache-poisoning vector that breaks routing / causes a denial of service. Advertise the header so caches key responses per-prefix. Signed-off-by: tittu.varghese <tittu.varghese@npci.org.in>
1 parent 24829c7 commit d9b6f88

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/app.controller.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export class AppController {
2424
@Get('*')
2525
index(@Req() req: Request, @Res() res: Response) {
2626
const basePath = resolveBasePath(req)
27+
// The injected <base href>/window.__BASE_PATH__ depend on X-Forwarded-Prefix,
28+
// so the response body varies by that header. Advertise it via Vary so any
29+
// CDN/intermediate proxy caches responses per-prefix instead of serving one
30+
// prefix's index.html to everyone (cache-poisoning / broken-routing risk).
31+
res.setHeader('Vary', 'X-Forwarded-Prefix')
2732
res.type('html').send(this.renderIndex(basePath))
2833
}
2934

0 commit comments

Comments
 (0)