Skip to content

ZCU-PUB/Fix dspace-customers 1083 R22: SSR cache keyed by origin and language, no static file outside static-files - #1753

Open
jr-rk wants to merge 1 commit into
customer/zcu-pubfrom
zcu-pub/fe-ssr-host-header-cache-key
Open

jr-rk wants to merge 1 commit into
customer/zcu-pubfrom
zcu-pub/fe-ssr-host-header-cache-key

Conversation

@jr-rk

@jr-rk jr-rk commented Nov 26, 2026

Copy link
Copy Markdown

References

Port of dtq-dev PR 1669 (commit 60f6ccb). dspace-customers issue 1083, finding R22.

Description

The SSR page caches were keyed by req.url only, 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 ..%2Findex is refused.

Instructions for Reviewers

  • server.ts and new ssr-cache-key.util.ts: the same as the source. Only the import block conflicted.
  • html-content.service.ts: not taken. On zcu it predates the dtq-dev static page rework ([Port to dtq-dev] static pages - SSR render; 404 behavior #1241): it only fetches a given URL and never reads the Host header, so the Host header part does not apply.
  • static-page.component.ts: zcu builds the static file URL here, so the isPlainFileName guard from the source goes here. A name that leaves static-files once decoded is not requested and the existing not-found state (404) is shown.
  • The title differs from the source because the Host header part does not apply.
  • Tests: ssr-cache-key.util.spec.ts and static-page.component.spec.ts with a new case for ..%2Findex (6 specs pass locally on Node 18). ESLint is clean on the changed files, yarn run build:prod passes. Not tested on a running SSR server.

Checklist

  • My PR is created against the branch it ports to
  • My PR is small in size
  • My PR follows the code conventions and passes ESLint
  • My PR passes the relevant specs and includes new or updated specs
  • My PR includes details on how to test it
  • No new dependencies, no new configuration

…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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The change alters security-sensitive SSR caching and standalone server routing, but lacks running Angular Universal/Express proxy validation for authenticated bypasses, origin/language isolation, and real URL/404 behavior.

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 static-files.

Changes:

  • Added origin-, language-, and URL-aware SSR cache keys.
  • Restricted bot-cache reads to anonymous requests.
  • Added static filename validation and regression tests for encoded path traversal.
File Description
src/​app/​static-page/​static-page.component.ts Rejects decoded static-page filenames containing path separators before fetching static content.
src/​app/​static-page/​static-page.component.spec.ts Tests that encoded traversal paths produce a 404 without fetching a file.
src/​app/​shared/​ssr-cache-key.util.ts Defines shared SSR cache-key generation using request origin, language, and URL.
src/​app/​shared/​ssr-cache-key.util.spec.ts Tests cache separation by language and request origin.
server.ts Uses the shared cache key and prevents authenticated requests from receiving bot-cache entries.

Review effort: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants