Files
HealthLog/src/lib/insights/values-back-link.ts
T
Marc-André Bombeck dbdc99a4a1 fix(insights): return values sub-page back-link to the originating metric
The show-all-readings link now carries the originating metric page as a
sanitised from param, so a weight to show-all drill-in returns to weight
rather than the Insights overview. The param is constrained to an internal
/insights/<slug> path so a crafted value cannot redirect off-site.
2026-06-03 08:56:20 +02:00

26 lines
984 B
TypeScript

/**
* v1.10.2 — resolve the back-link target for `/insights/values/[type]`.
*
* The "show all readings" link (built by `<SubPageShell>`) carries the
* originating metric page as a `from` query param so the values sub-page can
* return the user to where they drilled in from (e.g. `weight → show all
* values → back to weight`) rather than always to the Insights overview.
*
* The param is sanitised to an internal `/insights/<slug>` path — a single
* leading slash, no protocol / host, no protocol-relative `//` — so a crafted
* `?from=` value can never become an off-site or protocol-relative navigation
* target. Anything that fails the check falls back to the Insights overview.
*/
export const INSIGHTS_OVERVIEW = "/insights";
export function resolveValuesBackHref(from: string | null | undefined): string {
if (
from &&
from.startsWith("/insights/") &&
!from.startsWith("/insights//")
) {
return from;
}
return INSIGHTS_OVERVIEW;
}