-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[CHAIN] feat(ui): add fail-closed Registry access boundaries #12499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alejandrobailo
merged 1 commit into
feat/prowler-2414-registry-ui
from
feat/prowler-2414-registry-ui-03-access-boundaries
Sep 8, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { redirect } from "next/navigation"; | ||
|
|
||
| import { auth } from "@/auth.config"; | ||
| import { RegistryAccessBoundary } from "@/components/registry/registry-access-boundary"; | ||
| import { REGISTRY_ACCESS } from "@/lib/registry/access"; | ||
| import { evaluateRegistryAccess } from "@/lib/registry/access.server"; | ||
|
|
||
| export const dynamic = "force-dynamic"; | ||
|
|
||
| export default async function RegistryPage() { | ||
| const access = await evaluateRegistryAccess((await auth())?.accessToken); | ||
| if (access.status !== REGISTRY_ACCESS.ELIGIBLE) redirect("/profile"); | ||
| return ( | ||
| <RegistryAccessBoundary initialLeaseDurationMs={access.leaseDurationMs}> | ||
| {null} | ||
| </RegistryAccessBoundary> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
ui/components/registry/registry-access-boundary.integration.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { render } from "@/__tests__/render-browser"; | ||
|
|
||
| vi.mock("@/lib/registry/access.server", () => ({ | ||
| refreshRegistryEligibility: () => Promise.resolve({ status: "ineligible" }), | ||
| })); | ||
|
|
||
| import { RegistryAccessBoundary } from "./registry-access-boundary"; | ||
| import { RegistryEligibilityProvider } from "./registry-eligibility-provider"; | ||
|
|
||
| describe("RegistryAccessBoundary", () => { | ||
| it("unmounts protected Registry state after client access denial", async () => { | ||
| // Given / When | ||
| await render( | ||
| <RegistryEligibilityProvider> | ||
| <RegistryAccessBoundary initialLeaseDurationMs={30_000}> | ||
| <p>Protected Registry state</p> | ||
| </RegistryAccessBoundary> | ||
| </RegistryEligibilityProvider>, | ||
| ); | ||
|
|
||
| // Then | ||
| await expect | ||
| .poll(() => document.body.textContent) | ||
| .not.toContain("Protected Registry state"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| "use client"; | ||
|
|
||
| import { useRouter } from "next/navigation"; | ||
| import { type ReactNode, useEffect, useRef, useState } from "react"; | ||
|
|
||
| import { REGISTRY_ACCESS } from "@/lib/registry/access"; | ||
|
|
||
| import { useRegistryEligibility } from "./registry-eligibility-provider"; | ||
|
|
||
| export function RegistryAccessBoundary({ | ||
| children, | ||
| initialLeaseDurationMs, | ||
| }: { | ||
| children: ReactNode; | ||
| initialLeaseDurationMs: number; | ||
| }) { | ||
| const router = useRouter(); | ||
| const { generation, isEligible, status } = useRegistryEligibility(); | ||
| const expiresAt = useRef(Date.now() + initialLeaseDurationMs); | ||
| const [now, setNow] = useState(Date.now()); | ||
| const allowed = | ||
| isEligible || | ||
| (status === REGISTRY_ACCESS.UNKNOWN && | ||
| generation <= 1 && | ||
| now < expiresAt.current); | ||
|
|
||
| useEffect(() => { | ||
| const timer = window.setTimeout( | ||
| () => setNow(Date.now()), | ||
| Math.max(0, expiresAt.current - Date.now()), | ||
| ); | ||
| return () => window.clearTimeout(timer); | ||
| }, []); | ||
| useEffect(() => { | ||
| if (!allowed) router.replace("/profile"); | ||
| }, [allowed, router]); | ||
|
|
||
| return allowed ? children : null; | ||
| } | ||
78 changes: 78 additions & 0 deletions
78
ui/components/registry/registry-eligibility-provider.integration.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { render } from "@/__tests__/render-browser"; | ||
|
|
||
| const { refreshAccessMock } = vi.hoisted(() => ({ | ||
| refreshAccessMock: vi.fn(), | ||
| })); | ||
| vi.mock("@/lib/registry/access.server", () => ({ | ||
| refreshRegistryEligibility: refreshAccessMock, | ||
| })); | ||
|
|
||
| import { | ||
| RegistryEligibilityProvider, | ||
| useRegistryEligibility, | ||
| } from "./registry-eligibility-provider"; | ||
|
|
||
| function Probe() { | ||
| const { isEligible, status } = useRegistryEligibility(); | ||
| return <p>{isEligible ? "eligible" : status}</p>; | ||
| } | ||
|
|
||
| const renderProbe = () => | ||
| render( | ||
| <RegistryEligibilityProvider> | ||
| <Probe /> | ||
| </RegistryEligibilityProvider>, | ||
| ); | ||
|
|
||
| describe("RegistryEligibilityProvider", () => { | ||
| it("requires a server lease, renews visible access, and expires hidden access", async () => { | ||
| // Given | ||
| vi.useFakeTimers(); | ||
| refreshAccessMock.mockResolvedValue({ | ||
| status: "eligible", | ||
| leaseDurationMs: 30_000, | ||
| }); | ||
| const view = await renderProbe(); | ||
| await expect.element(view.getByText("eligible")).toBeVisible(); | ||
|
|
||
| // When | ||
| await vi.advanceTimersByTimeAsync(15_000); | ||
| Object.defineProperty(document, "visibilityState", { | ||
| configurable: true, | ||
| value: "hidden", | ||
| }); | ||
| await vi.advanceTimersByTimeAsync(30_000); | ||
|
|
||
| // Then | ||
| expect(refreshAccessMock).toHaveBeenCalledTimes(2); | ||
| await expect.element(view.getByText("unknown")).toBeVisible(); | ||
| vi.useRealTimers(); | ||
| Object.defineProperty(document, "visibilityState", { | ||
| configurable: true, | ||
| value: "visible", | ||
| }); | ||
| }); | ||
|
|
||
| it("rejects a late lease after a newer foreground denial", async () => { | ||
| // Given | ||
| let resolveFirst!: (value: unknown) => void; | ||
| refreshAccessMock | ||
| .mockImplementationOnce( | ||
| () => | ||
| new Promise<unknown>((resolve) => { | ||
| resolveFirst = resolve; | ||
| }), | ||
| ) | ||
| .mockResolvedValueOnce({ status: "ineligible" }); | ||
| const view = await renderProbe(); | ||
|
|
||
| // When | ||
| window.dispatchEvent(new Event("focus")); | ||
| resolveFirst!({ status: "eligible", leaseDurationMs: 30_000 }); | ||
|
|
||
| // Then | ||
| await expect.element(view.getByText("ineligible")).toBeVisible(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be missing some context about the requirements, but i see a lot of timing check if the user can access the registry, why is so crucial to be aware this fast? Should not be enought on each user token refresh and get the current permissions there?