Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix(models): reject inherited property names as tab slugs, prove redirects keep the record id (#4728)

[._.]/ Adam Eivya7c30fd7c34b
diff --git a/client/src/pages/Models.jsx b/client/src/pages/Models.jsx
index f9bcab082c..063100f157 100644
--- a/client/src/pages/Models.jsx
+++ b/client/src/pages/Models.jsx
@@ -74,13 +74,18 @@ export default function Models() {
// An unknown slug lands on Performance rather than rendering a blank page —
// it is the tab that answers "which model should I use?", which is what most
// people arrive here for.
- const activeTab = tab && TAB_CONTENT[tab] ? tab : null;
+ //
+ // OWN-property lookup, not plain indexing: the slug comes straight off the URL,
+ // so `/models/constructor` (or `toString`, `__proto__`) would otherwise resolve
+ // to an Object.prototype member, read as a valid tab, and get rendered as a
+ // component. Same reason `unavailableReasonLabel` guards its map.
+ const activeTab = tab && Object.hasOwn(TAB_CONTENT, tab) ? tab : null;
if (!activeTab) return <Navigate to="/models/performance" replace />;
// A record id in the URL selects the tab's drill-down, when it has one. A tab
// with no detail view ignores the extra segment and renders its index — better
// than 404ing a link that merely carries one segment too many.
- const DetailContent = recordId ? TAB_DETAIL[activeTab] : null;
+ const DetailContent = recordId && Object.hasOwn(TAB_DETAIL, activeTab) ? TAB_DETAIL[activeTab] : null;
const TabContent = TAB_CONTENT[activeTab];
return (
diff --git a/client/src/pages/Models.test.jsx b/client/src/pages/Models.test.jsx
index d1addd20b3..d714d5f036 100644
--- a/client/src/pages/Models.test.jsx
+++ b/client/src/pages/Models.test.jsx
@@ -82,6 +82,24 @@ describe('Models', () => {
expect(await screen.findByText('assessments panel')).toBeInTheDocument();
});
+ // The slug comes straight off the URL, so a plain `TAB_CONTENT[tab]` lookup
+ // resolves an Object.prototype member as a "valid" tab and hands it to React as
+ // a component. These must take the unknown-slug path like any other typo.
+ it.each(['constructor', 'toString', 'valueOf', 'hasOwnProperty'])(
+ 'treats the inherited property %s as an unknown tab',
+ async (slug) => {
+ renderAt(`/models/${slug}`);
+ expect(await screen.findByText('assessments panel')).toBeInTheDocument();
+ },
+ );
+
+ it('ignores a record id for a tab whose detail map inherits the name', async () => {
+ // Same hazard one level down: `TAB_DETAIL['constructor']` is a function, so an
+ // unguarded lookup would render it instead of falling back to the tab index.
+ renderAt('/models/loras/anything');
+ expect(await screen.findByText('loras panel')).toBeInTheDocument();
+ });
+
it('offers every Models destination in the sub-nav', () => {
renderAt('/models/performance');
for (const { label } of TABS) {
diff --git a/server/lib/navManifest.test.js b/server/lib/navManifest.test.js
index 3482bf333b..0b976cc031 100644
--- a/server/lib/navManifest.test.js
+++ b/server/lib/navManifest.test.js
@@ -439,6 +439,13 @@ const NAV_COVERAGE_OPT_OUT = new Map([
// real page and (loudly, not silently) demand a nav entry for its route.
const REDIRECT_ELEMENT = /element=\{<\s*(Navigate|RedirectWithSearch|PrefixRedirect|CanonRedirect|UniverseRouteRedirect)\b/;
+// Of those, the ones that REBASE a prefix and carry the trailing path (ids, tabs)
+// onto the new one. The others forward to a fixed destination and discard
+// whatever followed — correct for a static route, silently lossy for a param'd
+// one, which is how a bookmark into a specific record turns into a landing on
+// the index.
+const SUFFIX_PRESERVING_ELEMENTS = new Set(['PrefixRedirect', 'UniverseRouteRedirect']);
+
// Flatten a stack of (possibly multi-segment, possibly "/") route path pieces
// into a single absolute path: ['/', 'media', 'image'] → '/media/image'.
function joinRoutePath(segments) {
@@ -494,9 +501,10 @@ function scanRoutes(appSrc) {
// where each forwarding route points. `to` is read off the same line, so a
// `from`-only wrapper (CanonRedirect, UniverseRouteRedirect) records nothing
// rather than a bogus target.
- if (REDIRECT_ELEMENT.test(line)) {
+ const redirectElement = line.match(REDIRECT_ELEMENT);
+ if (redirectElement) {
const to = line.match(/\bto="([^"]*)"/);
- if (to) redirects.push({ from: absolute, to: to[1] });
+ if (to) redirects.push({ from: absolute, to: to[1], element: redirectElement[1] });
continue;
}
@@ -512,6 +520,7 @@ describe('nav coverage — every navigable App.jsx route has a manifest entry',
const navPaths = new Set(NAV_COMMANDS.map((c) => c.path.split(/[?#]/)[0]));
const scan = scanRoutes(fs.readFileSync(APP_JSX, 'utf8'));
const routePaths = new Set(scan.required);
+ const byFrom = new Map(scan.redirects.map((r) => [r.from, r]));
it('the line scanner saw every <Route> (single-line assumption holds)', () => {
// A non-empty malformed list or unbalanced stack means a multi-line route
@@ -536,14 +545,28 @@ describe('nav coverage — every navigable App.jsx route has a manifest entry',
// declaration then lives beside the path that moved, and the next move is one
// edit in navManifest.js instead of two files that can disagree.
it('keeps a redirect from every declared previous path to its current one', () => {
- const byFrom = new Map(scan.redirects.map((r) => [r.from, r.to]));
const broken = NAV_COMMANDS
.flatMap((c) => (c.previousPaths || []).map((from) => ({ from, to: c.path.split(/[?#]/)[0], id: c.id })))
- .filter(({ from, to }) => byFrom.get(from) !== to)
- .map(({ from, to, id }) => `${id}: ${from} → ${byFrom.get(from) ?? 'NO REDIRECT'} (want ${to})`);
+ .filter(({ from, to }) => byFrom.get(from)?.to !== to)
+ .map(({ from, to, id }) => `${id}: ${from} → ${byFrom.get(from)?.to ?? 'NO REDIRECT'} (want ${to})`);
expect(broken).toEqual([]);
});
+ // Landing on the right PAGE is only half of it. A previous path with a `:param`
+ // segment was a deep link into one record, so its redirect has to carry that
+ // segment across — swapping the PrefixRedirect for a bare <Navigate to="/models/training">
+ // still points at the right page and would pass the check above, while every
+ // bookmarked dataset quietly lands on the index instead.
+ it('preserves the record id when a parameterized previous path redirects', () => {
+ const lossy = NAV_COMMANDS
+ .flatMap((c) => (c.previousPaths || []).map((from) => ({ from, id: c.id })))
+ .filter(({ from }) => from.split('/').some((seg) => seg.startsWith(':')))
+ .map(({ from, id }) => ({ from, id, hit: byFrom.get(from) }))
+ .filter(({ hit }) => !hit || !SUFFIX_PRESERVING_ELEMENTS.has(hit.element))
+ .map(({ from, id, hit }) => `${id}: ${from} forwards via ${hit?.element ?? 'NO REDIRECT'}, which drops the trailing segment`);
+ expect(lossy).toEqual([]);
+ });
+
// The guard above is only as good as what it is pointed at, and it reads a
// field that is easy to simply not add. Pin the moves already made so deleting
// a `previousPaths` entry fails here rather than silently shrinking coverage.