feat: public WhatsApp webhook with signature checks on both sides
mobile-api answers Meta's handshake only for the right verify token and accepts events only with a valid X-Hub-Signature-256 under a company's app secret, capped at 1 MB and rate limited per IP, on an exact exemption. It forwards the exact bytes and signature; the WhatsApp service re-verifies them itself, so the ingest trusts no caller. The gateway exempts exactly POST /whatsapp/webhook/ingest from the user JWT, and the log redactor masks the handshake's token and challenge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
846c22697e
commit
a397de8c30
18 files changed
+759
-40
No files matched your search
+15
@@ -92,4 +92,19 @@ class JWTAuthFilterPublicRegistrationPathTest {
|
||||
assertThat(ex.getResponse().getStatusCode()).as(c[0] + " " + c[1]).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void whatsAppIngestIsPublicButOnlyThatExactPostPath() {
|
||||
assertThat(passes(call(HttpMethod.POST, "/whatsapp/webhook/ingest"))).isTrue();
|
||||
for (String[] c : new String[][] {
|
||||
{"GET", "/whatsapp/webhook/ingest"},
|
||||
{"POST", "/whatsapp/webhook/ingest/x"},
|
||||
{"POST", "/x/whatsapp/webhook/ingest"},
|
||||
{"POST", "/whatsapp/ownership/userChanged"},
|
||||
{"GET", "/whatsapp/conversations"} }) {
|
||||
MockServerWebExchange ex = call(HttpMethod.valueOf(c[0]), c[1]);
|
||||
assertThat(passes(ex)).as(c[0] + " " + c[1]).isFalse();
|
||||
assertThat(ex.getResponse().getStatusCode()).as(c[0] + " " + c[1]).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,4 +61,15 @@ class LogRedactorTest {
|
||||
.isEqualTo("/locationHierarchy/findParentByIdAndType/28/C");
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(1), () -> LogRedactor.path("/" + "eyJ.".repeat(20_000)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("query: WhatsApp webhook verify token and challenge values are masked, other params kept")
|
||||
void queryWebhookParamsMasked() {
|
||||
assertThat(LogRedactor.query("hub.mode=subscribe&hub.verify_token=S3cretTok&hub.challenge=998877"))
|
||||
.isEqualTo("hub.mode=subscribe&hub.verify_token=***&hub.challenge=***");
|
||||
assertThat(LogRedactor.query("hub.challenge=1&x=y&hub.verify_token=")).isEqualTo("hub.challenge=***&x=y&hub.verify_token=***");
|
||||
assertThat(LogRedactor.query("page=2&size=10")).isEqualTo("page=2&size=10");
|
||||
assertThat(LogRedactor.query(null)).isNull();
|
||||
assertThat(LogRedactor.query("")).isEmpty();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user