mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
fix(notifications): name the never-grantable refusal and redact the grant log
A loopback, link-local or metadata target answered private_origin_not_approved with a message telling the user to have the operator list it, and the parser refuses such an entry forever: a dead end the route test even pinned. Those targets now answer private_origin_not_grantable (catalogued, on all four routes, translated in seven locales) with a message that says no grant can open them and to use the relay's LAN address. Both senders carry the reason into the outcome so the test button forwards the same code. The malformed-entry warning printed the entry verbatim, which is where a pasted token or userinfo sits; the parser now hands callers scheme and host only, plus the reason in words. The Nightscout list throws a named error with that redacted entry and reason, and the connect route answers it as a 422 with the message instead of a bare 500, so a self-host that listed http://localhost:1337 reads what to change. The two settings cards translate a coded save refusal like the test button does; the docs and the changelog name the sub-host and sibling- port narrowing; the dispatcher floor tests assert the policy marker so a real NXDOMAIN cannot pass for a refusal. Refs #947
This commit is contained in:
1 parent
71175290af
commit
9c306f04e7
30 files changed
+436
-85
No files matched your search
@@ -13,7 +13,8 @@ import {
|
||||
import {
|
||||
evaluateNotificationTarget,
|
||||
isAllowedNotificationTarget,
|
||||
PRIVATE_ORIGIN_NOT_APPROVED,
|
||||
PRIVATE_ORIGIN_NOT_APPROVED_CODE,
|
||||
PRIVATE_ORIGIN_NOT_GRANTABLE_CODE,
|
||||
} from "@/lib/notifications/egress-policy";
|
||||
import { encrypt, decrypt } from "@/lib/crypto";
|
||||
import { NextRequest } from "next/server";
|
||||
@@ -32,6 +33,8 @@ const webhookSettingsSchema = webhookSettingsSchemaWith(
|
||||
|
||||
const PRIVATE_ORIGIN_REFUSAL =
|
||||
"This address is on a private network. The operator has to list its exact origin (scheme://host:port) in NOTIFICATION_PRIVATE_ORIGINS before HealthLog can send to it.";
|
||||
const NOT_GRANTABLE_REFUSAL =
|
||||
"This address is loopback, link-local or a metadata address, which no operator grant can open. Use the relay's LAN address instead.";
|
||||
|
||||
/**
|
||||
* Generic-webhook channel config (v1.17.1).
|
||||
@@ -139,18 +142,26 @@ export const PUT = apiHandler(async (request: NextRequest) => {
|
||||
// adds the code and a message naming the operator's lever (#947).
|
||||
const issues = sanitiseZodIssues(parsed.error.issues);
|
||||
const candidate = (body as { url?: unknown } | null)?.url;
|
||||
const reason =
|
||||
typeof candidate === "string"
|
||||
? evaluateNotificationTarget(candidate).reasonCode
|
||||
: null;
|
||||
if (
|
||||
typeof candidate === "string" &&
|
||||
evaluateNotificationTarget(candidate).reasonCode ===
|
||||
PRIVATE_ORIGIN_NOT_APPROVED
|
||||
reason === PRIVATE_ORIGIN_NOT_APPROVED_CODE ||
|
||||
reason === PRIVATE_ORIGIN_NOT_GRANTABLE_CODE
|
||||
) {
|
||||
annotate({
|
||||
action: { name: "settings.webhook.update" },
|
||||
meta: { refused: PRIVATE_ORIGIN_NOT_APPROVED },
|
||||
});
|
||||
return apiValidationError(PRIVATE_ORIGIN_REFUSAL, issues, 422, {
|
||||
errorCode: PRIVATE_ORIGIN_NOT_APPROVED,
|
||||
meta: { refused: reason },
|
||||
});
|
||||
return apiValidationError(
|
||||
reason === PRIVATE_ORIGIN_NOT_GRANTABLE_CODE
|
||||
? NOT_GRANTABLE_REFUSAL
|
||||
: PRIVATE_ORIGIN_REFUSAL,
|
||||
issues,
|
||||
422,
|
||||
{ errorCode: reason },
|
||||
);
|
||||
}
|
||||
return apiValidationError("Invalid data", issues, 422);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,9 @@ export const POST = apiHandler(async () => {
|
||||
meta: { success: false, refused: result.errorCode },
|
||||
});
|
||||
return apiError(
|
||||
"The target is on a private network the operator has not approved. List its exact origin (scheme://host:port) in NOTIFICATION_PRIVATE_ORIGINS on the server.",
|
||||
result.errorCode === "private_origin_not_grantable"
|
||||
? "The target is loopback, link-local or a metadata address, which no operator grant can open. Use the relay's LAN address instead."
|
||||
: "The target is on a private network the operator has not approved. List its exact origin (scheme://host:port) in NOTIFICATION_PRIVATE_ORIGINS on the server.",
|
||||
422,
|
||||
{ errorCode: result.errorCode },
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user