Repository navigation
Conversation
…uage, no static file outside static-files Port of dtq-dev-93 PR 1718 (commit fd7cd1c), the v9 port of dtq-dev PR 1669. - server.ts and ssr-cache-key.util(.spec).ts as in 1718; only the import block next to the jcu ssr-cache-stats import conflicted. - jcu has its own browser-only html-content.service that never reads the Host header, so the origin part of 1718 does not apply. Only the isPlainFileName guard is added to getHtmlContentByPathAndLocale, with a new spec for it.
There was a problem hiding this comment.
🟡 Changes recommended
A critical cache-key issue remains: requests with different Accept-Language values can receive the wrong localized SSR HTML when no valid language cookie is present.
1 open issue
What changed in this PR
This pull request hardens SSR page caching by separating cached renders by origin and language, preventing authenticated users from receiving bot-cache entries, and rejecting encoded path traversal in static-file requests.
Changes:
- Added origin-, language-, and URL-aware SSR cache keys.
- Restricted bot-cache reads to anonymous requests.
- Added static filename validation and focused unit tests.
| File | Description |
|---|---|
| src/app/shared/ssr-cache-key.util.ts | Defines composite SSR cache keys using request origin, language-cookie context, and URL. |
| src/app/shared/ssr-cache-key.util.spec.ts | Tests SSR cache-key separation by language and request origin. |
| src/app/shared/html-content.service.ts | Rejects decoded filenames containing path separators before fetching static content. |
| src/app/shared/html-content.service.spec.ts | Verifies encoded traversal-style filenames do not trigger requests. |
| server.ts | Uses the new SSR cache keys and prevents authenticated requests from reading bot-cache entries. |
Review effort: Lite
| * @param req current request | ||
| */ | ||
| export function getSsrCacheKey(req: Request): string { | ||
| return JSON.stringify([req.protocol, req.get('host'), req.cookies?.[LANG_COOKIE], req.url]); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

References
Port of dtq-dev-93 PR 1718 (commit fd7cd1c), the v9 port of dtq-dev PR 1669. dspace-customers issue 1083, finding R22.
In comparison with the source, the customized diff is based on jcu rewriting html-content.service.ts in #1478 so that it loads static pages only in the browser and never reads the Host header, so the Host header part does not apply. Only the same isPlainFileName guard from the source is added to jcu's getHtmlContentByPathAndLocale, with a new spec, because jcu had none for this service. The SSR cache stats endpoint now lists the new keys; it only lists them, so nothing else changes.
Description
The SSR page caches were keyed by
req.urlonly, and the bot cache was read before the login check. Now the key holds origin, path and language, the bot cache serves only anonymous requests, and a static page name like..%2Findexis refused.Instructions for Reviewers
server.tsand newssr-cache-key.util.ts: the same as the source. Only the import block next to the jcussr-cache-statsimport conflicted.html-content.service.ts: jcu has its own browser-only version (Add deployed-version info: VERSION_D at /static/VERSION_D (#813) #1478) that never reads theHostheader, so the Host header part does not apply. Only theisPlainFileNameguard is added togetHtmlContentByPathAndLocale.html-content.service.spec.tswith one test for the guard (..%2Findexmakes no request); jcu had no spec for this service.ssr-cache-key.util.spec.tsandhtml-content.service.spec.ts(3 specs pass locally on Node 20). ESLint is clean on the changed files,npm run build:prodpasses. Not tested on a running SSR server.Checklist