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:
ngqileandClaude Opus 5.5 committed 2026-12-02 11:03:56 +08:00
1 parent 846c22697e
commit a397de8c30
18 files changed
+759 -40

No files matched your search

@@ -57,7 +57,9 @@ public class JWTAuthFilter implements GlobalFilter, Ordered {
publicPath(HttpMethod.POST, "/counter/checkin/lookup"),
publicPath(HttpMethod.POST, "/counter/checkin/byGuest"),
// Password hint on public password screens: switched-on rule names and numbers only, no user data
publicPath(HttpMethod.GET, "/passwordRule/adminActive"));
publicPath(HttpMethod.GET, "/passwordRule/adminActive"),
// WhatsApp webhook forward from mobile-api: no user token; the service re-verifies Meta's signature itself
publicPath(HttpMethod.POST, "/whatsapp/webhook/ingest"));
private static Map.Entry<HttpMethod, Pattern> publicPath(HttpMethod method, String regex) {
return Map.entry(method, Pattern.compile(regex));
@@ -37,6 +37,30 @@ final class LogRedactor {
return sb.toString();
}
/** Query params whose values never reach a log: Meta's webhook handshake sends the verify token and challenge in the URL. */
private static final List<String> SENSITIVE_PARAMS = List.of("hub.verify_token=", "hub.challenge=");
/** The raw query string with the values of the sensitive params masked. */
static String query(String rawQuery) {
if (rawQuery == null || rawQuery.isEmpty()) {
return rawQuery;
}
StringBuilder sb = new StringBuilder(rawQuery.length());
int start = 0;
while (start <= rawQuery.length()) {
int amp = rawQuery.indexOf('&', start);
String pair = rawQuery.substring(start, amp < 0 ? rawQuery.length() : amp);
String name = SENSITIVE_PARAMS.stream().filter(pair::startsWith).findFirst().orElse(null);
sb.append(name == null ? pair : name + MASK);
if (amp < 0) {
break;
}
sb.append('&');
start = amp + 1;
}
return sb.toString();
}
/** Path prefixes followed by a bearer-style invite, check-in or registration-link token. */
private static final List<String> TOKEN_PREFIXES = List.of("/counter/eventGuest/findByToken/", "/counter/checkin/findEvent/",
"/counter/registrationLink/findByToken/");