send notice ids in the request body (#25142)

Notice ids went into the URL path, and nginx decodes the path, merges slashes, and resolves dot segments before proxying. A detector named zmq:tcp://host:5555 came through as tcp:/host, so its notice 404'd and couldn't be acknowledged or muted. The same happened to failed_login notices for usernames containing // or /../. Acknowledge, mute, and unhide now take the id in a JSON body at /notices/acknowledge, /notices/mute, and /notices/unhide.
This commit is contained in:
Josh Hawkins
2026-12-02 08:28:38 -07:00
committed by GitHub
parent 31038a9e14
commit 0cb1e7bbfb
7 changed files with 109 additions and 73 deletions
+20 -14
View File
@@ -57,12 +57,12 @@ const EVENT_NOTICE = {
muted_at: null,
};
// a repeated device gets a '#2' suffix, which a raw URL would cut off as a fragment
const SUFFIXED_NOTICE = {
// nginx would merge the slashes if this id went in the URL path
const ZMQ_NOTICE = {
...EVENT_NOTICE,
id: "detector_stuck:openvino:GPU#2",
scope: "openvino:GPU#2",
params: { detector: "openvino:GPU#2" },
id: "detector_stuck:zmq:tcp://host:5555",
scope: "zmq:tcp://host:5555",
params: { detector: "zmq:tcp://host:5555" },
};
test.describe("System — Health tab @medium", () => {
@@ -103,17 +103,17 @@ test.describe("System — Health tab @medium", () => {
for (const action of ["acknowledge", "mute"] as const) {
test(`${action} posts and removes the row`, async ({ frigateApp }) => {
const path = `/api/notices/${encodeURIComponent(SUFFIXED_NOTICE.id)}/${action}`;
const path = `/api/notices/${action}`;
await frigateApp.installDefaults({
config: RESTREAMED,
stats: QUIET_STATS,
notices: [SUFFIXED_NOTICE],
notices: [ZMQ_NOTICE],
});
// the list shrinks after the POST so the refetch shows the row gone
let hidden = false;
await frigateApp.page.route("**/api/notices", (route) =>
route.fulfill({ json: hidden ? [] : [SUFFIXED_NOTICE] }),
route.fulfill({ json: hidden ? [] : [ZMQ_NOTICE] }),
);
await frigateApp.page.route(
(url) => url.pathname.endsWith(path),
@@ -126,10 +126,12 @@ test.describe("System — Health tab @medium", () => {
await frigateApp.goto("/system#health");
const request = frigateApp.page.waitForRequest(
(req) =>
new URL(req.url()).pathname.endsWith(path) && req.method() === "POST",
new URL(req.url()).pathname.endsWith(path) &&
req.method() === "POST" &&
req.postDataJSON()?.id === ZMQ_NOTICE.id,
);
await frigateApp.page
.getByTestId(`health-problem-notice:${SUFFIXED_NOTICE.id}`)
.getByTestId(`health-problem-notice:${ZMQ_NOTICE.id}`)
.getByRole("button", {
name: action === "mute" ? "Mute" : "Acknowledge",
exact: true,
@@ -272,7 +274,7 @@ test.describe("System — Health tab @medium", () => {
url.searchParams.get("include_hidden") === "true",
(route) => route.fulfill({ json: [MUTED_NOTICE] }),
);
const path = `/api/notices/${encodeURIComponent(MUTED_NOTICE.id)}/hidden`;
const path = "/api/notices/unhide";
await frigateApp.page.route(
(url) => url.pathname.endsWith(path),
(route) => route.fulfill({ json: { success: true } }),
@@ -285,7 +287,9 @@ test.describe("System — Health tab @medium", () => {
const request = frigateApp.page.waitForRequest(
(req) =>
new URL(req.url()).pathname.endsWith(path) && req.method() === "DELETE",
new URL(req.url()).pathname.endsWith(path) &&
req.method() === "POST" &&
req.postDataJSON()?.id === MUTED_NOTICE.id,
);
await frigateApp.page
.getByTestId(
@@ -1356,7 +1360,7 @@ test.describe("System — Health notices sources @medium", () => {
// the list gains the mute after the POST so the refetch hides the row
let muted = false;
const path = `/api/notices/${encodeURIComponent(id)}/mute`;
const path = "/api/notices/mute";
await frigateApp.page.route(
(url) => url.pathname.endsWith(path),
(route) => {
@@ -1376,7 +1380,9 @@ test.describe("System — Health notices sources @medium", () => {
);
const request = frigateApp.page.waitForRequest(
(req) =>
new URL(req.url()).pathname.endsWith(path) && req.method() === "POST",
new URL(req.url()).pathname.endsWith(path) &&
req.method() === "POST" &&
req.postDataJSON()?.id === id,
);
await row.getByRole("button", { name: "Mute", exact: true }).click();
await request;
+2 -2
View File
@@ -58,7 +58,7 @@ export function useHealthProblems(
const muteCheck = useCallback(
async (id: string) => {
await axios.post(`notices/${encodeURIComponent(id)}/mute`);
await axios.post("notices/mute", { id });
mutateMutedChecks();
},
[mutateMutedChecks],
@@ -66,7 +66,7 @@ export function useHealthProblems(
const unmuteCheck = useCallback(
async (id: string) => {
await axios.delete(`notices/${encodeURIComponent(id)}/hidden`);
await axios.post("notices/unhide", { id });
mutateMutedChecks();
},
[mutateMutedChecks],
+3 -5
View File
@@ -60,17 +60,15 @@ export function useNotices(showHidden: boolean) {
);
const acknowledge = useCallback(
(id: string) =>
act(axios.post(`notices/${encodeURIComponent(id)}/acknowledge`)),
(id: string) => act(axios.post("notices/acknowledge", { id })),
[act],
);
const mute = useCallback(
(id: string) => act(axios.post(`notices/${encodeURIComponent(id)}/mute`)),
(id: string) => act(axios.post("notices/mute", { id })),
[act],
);
const unhide = useCallback(
(id: string) =>
act(axios.delete(`notices/${encodeURIComponent(id)}/hidden`)),
(id: string) => act(axios.post("notices/unhide", { id })),
[act],
);