From 581c8c2a053d0825e1729cad2fcdad735b2c4fe3 Mon Sep 17 00:00:00 2001 From: Danilo Lakovic Date: Sat, 21 Nov 2026 08:57:52 +0100 Subject: [PATCH 1/2] Test that a refused read of the roles list does not start a session check --- src/entities/sdk-setup.test.ts | 14 +++++++++ src/session/request-policy.test.ts | 47 ++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/entities/sdk-setup.test.ts b/src/entities/sdk-setup.test.ts index d25226e7..68e782e9 100644 --- a/src/entities/sdk-setup.test.ts +++ b/src/entities/sdk-setup.test.ts @@ -1,4 +1,5 @@ import { loginRead } from '@pulp-ui/sdk/core/login'; +import { rolesList } from '@pulp-ui/sdk/core/roles'; import { statusRead } from '@pulp-ui/sdk/core/status'; import { tasksDelete, tasksRead } from '@pulp-ui/sdk/core/tasks'; import { HttpResponse, http } from 'msw'; @@ -243,6 +244,19 @@ describe('the sdk and the session', () => { return { arrived, release }; } + it('asks who is signed in nothing for a refused read of the roles list, and leaves the refusal to its caller', async () => { + setSignedIn(true); + refuse('*/pulp/api/v3/roles/', 403, 'Forbidden here.'); + const logins = recordHits('*/pulp/api/v3/login/'); + + const error = await rolesList({ fields: ['name'] }).catch((e) => e); + + expect(requestErrorStatus(error)).toBe(403); + expect(isSessionEnd(error)).toBe(false); + expect(logins).toHaveLength(0); + expect(getSnapshot().ended).toBe(false); + }); + it('ignores the 401 of a call sent before the session was resumed', async () => { setSignedIn(true); const held = holdAnswer('*/pulp/api/v3/status/', 401); diff --git a/src/session/request-policy.test.ts b/src/session/request-policy.test.ts index 33af2561..2d1d42b6 100644 --- a/src/session/request-policy.test.ts +++ b/src/session/request-policy.test.ts @@ -320,6 +320,53 @@ describe('handleFailure', () => { expect(check).not.toHaveBeenCalled(); }); + it.each([ + '/pulp/api/v3/roles/?fields=name%2Cpermissions&limit=1000', + '/pulp/api/v3/roles/', + 'roles/?limit=1', + ])( + 'asks nothing for a 403 of a read of the roles list (%s), which is the answer to what the account may read', + async (url) => { + setSignedIn(true); + const check = vi.fn(); + const error = answer(403); + + await handleFailure( + 403, + url, + error, + check, + prepareRequest(url, 'GET', new Headers()), + ); + + expect(check).not.toHaveBeenCalled(); + expect(isMarkedSessionEnd(error)).toBe(false); + expect(getSnapshot().ended).toBe(false); + }, + ); + + it.each([ + ['a read of one role', 'GET', '/pulp/api/v3/roles/0001/'], + ['the roles of a user', 'GET', '/pulp/api/v3/users/1/roles/'], + ['the roles of a group', 'GET', '/pulp/api/v3/groups/1/roles/'], + ['a role being made', 'POST', '/pulp/api/v3/roles/'], + ['a role being removed', 'DELETE', '/pulp/api/v3/roles/'], + ['a list that only ends alike', 'GET', '/pulp/api/v3/things/roles/'], + ])('still asks about the session for a 403 of %s', async (_, method, url) => { + setSignedIn(true); + const check = vi.fn(() => Promise.resolve({ username: 'zoe' })); + + await handleFailure( + 403, + url, + answer(403), + check, + prepareRequest(url, method, new Headers()), + ); + + expect(check).toHaveBeenCalledTimes(1); + }); + it('shares one check between refusals that arrive together, whoever asks', async () => { setSignedIn(true); let finish: (value: unknown) => void = () => undefined; From 943b2b5bd25c5ce875d09f037cf3d19291d5e387 Mon Sep 17 00:00:00 2001 From: Danilo Lakovic Date: Sat, 21 Nov 2026 08:59:58 +0100 Subject: [PATCH 2/2] Do not check the session when the roles list is refused A limited account is refused the list of roles by the server's access rules, and the screens that read it take the refusal as their answer and fall back to the account's own role assignments. Every refusal of a signed-in user started a who-is-signed-in request to tell an ended session from a plain refusal, so each such screen made the same sign-in read twice. A refused read of the roles list itself no longer starts it; any other request of an ended session is refused as before and reports the end. --- src/session/request-policy.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/session/request-policy.ts b/src/session/request-policy.ts index 5cd720fd..fef9a86f 100644 --- a/src/session/request-policy.ts +++ b/src/session/request-policy.ts @@ -74,6 +74,21 @@ export function isLoginUrl(url: string): boolean { return path.slice(prefix?.length ?? 0).startsWith('login/'); } +// Whether the URL is the list of roles. Whoever may not read it is refused, +// and that refusal is the answer the caller asked for (what the account may +// read), not a sign that the session ended: a screen reads this list to learn +// what an account may do, and a limited account is refused it by the server's +// access rules. Only the list itself counts, not one role and not the roles +// of a user or group, which are asked for other reasons. +export function isRolesListUrl(url: string): boolean { + const path = collapseDoubleSlash(url); + const prefix = [config.API_BASE_PATH, SCHEMA_API_ROOT].find((candidate) => + path.startsWith(candidate), + ); + + return (path.slice(prefix?.length ?? 0).split('?')[0] ?? '') === 'roles/'; +} + // The methods the server checks the CSRF token of: those that change state. const UNSAFE_METHODS = new Set(['POST', 'PUT', 'PATCH', 'DELETE']); @@ -166,6 +181,9 @@ const isForOlderSession = (context: IRequestContext | undefined) => // who-is-signed-in request, made by `checkSession`, tells them apart: a 2xx // answer means the refusal is real and the error reaches the caller // untouched; a 401 or 403 answer means the session ended. +// The one read that is no occasion for that request is the roles list: its +// refusal is an answer, and any later request of an ended session is refused +// again and tells. export async function handleFailure( status: number | undefined, url: string, @@ -179,7 +197,11 @@ export async function handleFailure( if (status === 401) { reportUnauthorized('request'); - } else if (status === 403 && isSignedIn()) { + } else if ( + status === 403 && + isSignedIn() && + !(context?.method === 'GET' && isRolesListUrl(url)) + ) { if ((await sessionEnded(checkSession)) && !isForOlderSession(context)) { markSessionEnd(error); reportUnauthorized('request');