deny proxy users whose role can't be resolved instead of falling back to viewer

Proxy role resolution fell back to viewer, which grants every camera, in several accidental cases. A default_role that was misspelled, null, or named a deleted role became viewer. A role_map group whose mapped role had been deleted (for example, emptied by a camera delete) got the default role. Direct role headers were lowercased but compared to case-sensitive role names, so a custom role like Garage never matched, and a custom role named Admin resolved to the built-in admin.

- match header values, default_role and role_map roles against configured roles regardless of case
- deny when default_role or a matched role_map role doesn't exist, and warn at config load for an unknown default_role
- reserve admin and viewer in every casing and reject role names that differ only by case, in config validation and the Create Role dialog
- show a null default_role as none in the settings widget
This commit is contained in:
Josh Hawkins
2026-11-23 09:34:33 -06:00
parent 3bca9b8676
commit 47fcb90893
8 changed files with 91 additions and 27 deletions
@@ -29,7 +29,13 @@ export function DefaultRoleWidget(props: WidgetProps) {
return [...BUILT_IN_ROLES, ...custom, NONE_ROLE];
}, [formContext]);
const selectedValue = typeof value === "string" && value ? value : "viewer";
// A null default denies access, so it displays as none
const selectedValue =
value === null
? NONE_ROLE
: typeof value === "string" && value
? value
: "viewer";
const getLabel = (role: string) =>
BUILT_IN_ROLES.includes(role) || role === NONE_ROLE
@@ -61,7 +61,9 @@ export default function CreateRoleDialog({
(config.cameras[b]?.ui?.order ?? 0),
);
const existingRoles = Object.keys(config.auth?.roles || {});
const existingRoles = Object.keys(config.auth?.roles || {}).map((role) =>
role.toLowerCase(),
);
const formSchema = z.object({
role: z
@@ -70,7 +72,7 @@ export default function CreateRoleDialog({
.regex(/^[A-Za-z0-9._]+$/, {
message: t("roles.dialog.form.role.roleOnlyInclude"),
})
.refine((role) => !existingRoles.includes(role), {
.refine((role) => !existingRoles.includes(role.toLowerCase()), {
message: t("roles.dialog.form.role.roleExists"),
}),
cameras: z