Skip to content

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
customer/zcu-datafrom
zcu-data/fe-ssr-host-header-cache-key
Open

jr-rk wants to merge 1 commit into
customer/zcu-datafrom
zcu-data/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. Same change as the zcu-pub port (#1753).

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

  • Identical to the zcu-pub port: static-page.component.ts, its spec and html-content.service.ts are the same files on both branches, and server.ts applied without conflict.
  • server.ts and new ssr-cache-key.util.ts: the same as the source.
  • html-content.service.ts: not taken. It only fetches a given URL and never reads the Host header, so the Host header part does not apply.
  • static-page.component.ts: the isPlainFileName guard, because zcu builds the static file URL here.
  • Tests: ssr-cache-key.util.spec.ts and static-page.component.spec.ts (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.
@jr-rk jr-rk self-assigned this Nov 26, 2026
@jr-rk
jr-rk requested a lite review from Copilot November 26, 2026 10:16

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

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

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