Reviewer · Security
Embed authorization checks
When refactoring UI or logic into reusable/embeddable components (e.g., a provider meant to be mounted inside another app's page), do not silently drop the authorization checks that were enforced by the original wrapping layout. If a component previously relied on a parent layout (such as an `AppRoutes` wrapper) to gate access by role or capability, that...
When refactoring UI or logic into reusable/embeddable components (e.g., a provider meant to be mounted inside another app’s page), do not silently drop the authorization checks that were enforced by the original wrapping layout. If a component previously relied on a parent layout (such as an AppRoutes wrapper) to gate access by role or capability, that check must travel with the extracted component rather than being left to the discretion of every future caller.
Prefer defense in depth: have the component itself verify the required capabilities/roles and render nothing (or an explicit PermissionsError/denial state) when the user is unauthorized, rather than assuming the host will remember to check. If embedding an authorization check directly isn’t feasible, the component’s public API/docstring must explicitly and prominently state that callers are responsible for performing the authz check before rendering it, and ideally the component should fail closed by default rather than fail open.
Example of the safer pattern:
export const EmbeddedIntegrationsProvider: React.FC<EmbeddedIntegrationsProviderProps> = memo(
({ initialPath, children }) => {
const authz = useAuthz();
if (!authz.integrations.readIntegrationPolicies && !authz.integrations.all && !authz.fleet.all) {
return <PermissionsError />;
}
// ... render providers and children
}
);
Apply this standard whenever extracting a component from a page/route that previously enforced authorization, or when building new embeddable/shared components that expose sensitive data or privileged actions.</description>