Repository navigation
ZCU-DATA/Fix dspace-customers 1083 R22: SSR cache keyed by origin and language, no static file outside static-files - #1755
Open
jr-rk wants to merge 1 commit into
Conversation
… language, no static file outside static-files Port of dtq-dev PR 1669 (commit 60f6ccb). - server.ts and ssr-cache-key.util(.spec).ts: the dtq-dev change as is; only the import block in server.ts conflicted. - html-content.service on zcu predates the dtq-dev static page rework (#1241): it only fetches a given URL and never reads the Host header, so that part of 1669 does not apply and the service and its spec are left out. zcu builds the static file URL in StaticPageComponent, so the isPlainFileName guard goes there, with a spec case.
There was a problem hiding this comment.
🔵 Needs a closer look
Security-sensitive SSR cache isolation and traversal handling lack validation on a running server, including proxy, host/language, authenticated bot, and encoded-path scenarios, so human verification is still needed.
No open issues 🎉
What changed in this PR
This PR hardens SSR caching and static-page loading by isolating cached renders by origin and language, preventing authenticated users from receiving bot-cache responses, and rejecting encoded paths that could escape the static-files directory.
Changes:
- Adds origin-, language-, and URL-aware SSR cache keys.
- Restricts bot-cache reads to anonymous requests.
- Validates static-page filenames and adds regression tests for encoded traversal paths.
| File | Description |
|---|---|
| src/app/static-page/static-page.component.ts | Validates static-page filenames before requesting content. |
| src/app/static-page/static-page.component.spec.ts | Tests rejection of encoded traversal paths. |
| src/app/shared/ssr-cache-key.util.ts | Defines SSR cache keys using protocol, host, language, and URL. |
| src/app/shared/ssr-cache-key.util.spec.ts | Tests cache-key separation by language and request origin. |
| server.ts | Applies the new cache key and prevents authenticated requests from reading bot-cache entries. |
Review effort: Lite
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 PR 1669 (commit 60f6ccb). dspace-customers issue 1083, finding R22. Same change as the zcu-pub port (#1753).
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
static-page.component.ts, its spec andhtml-content.service.tsare the same files on both branches, andserver.tsapplied without conflict.server.tsand newssr-cache-key.util.ts: the same as the source.html-content.service.ts: not taken. It only fetches a given URL and never reads theHostheader, so the Host header part does not apply.static-page.component.ts: theisPlainFileNameguard, because zcu builds the static file URL here.ssr-cache-key.util.spec.tsandstatic-page.component.spec.ts(6 specs pass locally on Node 18). ESLint is clean on the changed files,yarn run build:prodpasses. Not tested on a running SSR server.Checklist