docs(openspec): propose stop-gateway-body-logging

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-11-27 18:18:37 +08:00
1 parent e271c06e07
commit f81202f46c
5 files changed
+151

No files matched your search

@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-27
@@ -0,0 +1,28 @@
# Design
## Context
`RequestBodyLoggerFilter` is a global gateway filter (order -200, before `JWTAuthFilter` at -100). For a GET it logs method, path and headers. For any other method it reads the whole body into memory, logs it through `LogRedactor.body` (JSON and form fields whose names contain password, pwd, secret or token are masked; other content types and bodies over 64 KB are logged by size only), then re-wraps the cached bytes in a request decorator with a fixed Content-Length. No other gateway filter reads the body. See proposal.md for why bodies must go.
## Goals / Non-Goals
**Goals:** no request body content in the gateway log, for every method and content type; downstream requests unchanged.
**Non-Goals:** changing what mobile-api or the services log; changing the skip list or the header and path masking.
## Decisions
1. **Log every method the way GET is logged today.** One line, `Method`, masked `Path`, masked `Headers`, then pass the exchange on untouched. Content-Length is part of the headers, so the body size stays visible.
- Alternative: keep reading the body to log its size. Rejected: the header already carries the size for non-chunked bodies, and reading the body is the only reason the filter buffers whole requests in memory and rebuilds them.
- Alternative: mask known PII field names (name, mobile, email). Rejected by the user: a denylist misses fields it does not name.
2. **Delete the body-masking code.** `LogRedactor.body`, the JSON and form maskers, `isSensitiveName`, the size constants and their tests have no callers once the filter stops logging bodies. `headers` and `path` stay. The deleted `LogRedactorTest` cases test only removed code: `jsonAnyValueTypeMasked`, `jsonEscapedKeyMasked`, `jsonWithoutContentType`, `brokenJsonNotLogged`, `formMasked`, `otherBodiesNotLogged`, `sizeLimits`, `adversarialBodiesAreLinear`.
3. **Rewrite the body assertions in `RequestBodyLoggerFilterTest`.** `customerLoginPasswordMasked`, `sensitiveFieldsMasked` and `formPasswordMasked` assert a masked body today. They become "no body content in the log" tests, which also forbid the non-secret fields (username, name) the old tests required. Each still checks the downstream body is unchanged. `emptyBody` asserted the `(empty)` marker; it now asserts the line is logged and the request is forwarded. A new test covers a lead update body and a query string.
## Risks / Trade-offs
- [Bodies are no longer available in the log for debugging] → Method, path, headers and size remain. A service can log a specific, non-PII field itself where it needs one.
- [A future change re-adds body logging] → The spec forbids it, and the filter test fails if any body content reaches the log.
## Migration Plan
Deploy the gateway. Rollback is redeploying the previous gateway image. No data or contract changes. Bodies already in Elasticsearch are not touched by this change; whether to purge them is a separate operational decision.
@@ -0,0 +1,36 @@
# Proposal
## Why
The API gateway logs the body of every POST and PUT request, and the log is shipped to Elasticsearch. Only credentials are masked (passwords, tokens, keys). Every other field is logged as sent, so personal data reaches the log:
- lead capture, lead update and lead search (names, mobiles, emails, notes);
- member calls;
- admin user create and edit;
- forgot-password.
The project rules forbid logging customer PII. The `add-lead-listing-export` branch review found this, and it has to be fixed before go-live on 2027-01-15.
## What Changes
- The gateway request log keeps one line per request with the method, the path and the headers, and never the request body. Credential header values and JWT-shaped path segments stay masked, as today.
- The gateway no longer reads the request body to log it, so the body passes to the downstream service untouched. No other gateway filter reads the body.
- The body-masking code (JSON and form field masking, size limits) has no callers left and is removed, together with its unit tests. Header and path masking and their tests stay.
- The filter tests that asserted a masked body now assert that no body content reaches the log at all, and that the downstream service still receives the original body. These tests get stricter, not weaker.
- The skip list (`/log/save`, `/log/saveMemberLog`, `/auth/authenticate`, `/auth/webMemberAuthenticate`) and the `/actuator` skip stay as they are.
Not in this change: logging elsewhere (mobile-api and service logs), log retention, and access logs.
## Capabilities
### New Capabilities
- `gateway-request-logging`: what the gateway writes to its request log, and what it must never write there.
### Modified Capabilities
None.
## Impact
- `solvway-api-gateway`: `RequestBodyLoggerFilter` (logs without reading the body), `LogRedactor` (body masking removed), and their tests.
- **Debugging**: request bodies are no longer in the gateway log. Content-Length is still logged with the headers, so the size of each body stays visible.
- No API, database or dependency change. Downstream services see the same requests.
@@ -0,0 +1,61 @@
## Purpose
The gateway keeps a log line for each request it routes, so operators can trace traffic, without ever writing request bodies, personal data or credentials to that log.
## ADDED Requirements
### Requirement: Request log carries no request body
The gateway SHALL log each routed request, except skip-listed and `/actuator` paths, as one line with the method, the path and the request headers. It MUST NOT write any part of the request body to the log, for any method or content type. The downstream service MUST receive the original request body unchanged.
#### Scenario: Lead update body stays out of the log
- **GIVEN** a PUT or POST with a JSON body holding a lead's name, mobile, email and notes
- **WHEN** the gateway routes it
- **THEN** the log line holds the method and the path
- **AND** none of the name, mobile, email or notes appears in the log
- **AND** the downstream service receives the body byte for byte
#### Scenario: Login body stays out of the log
- **GIVEN** a customer login POST with a username and a password in a JSON body
- **WHEN** the gateway routes it
- **THEN** neither the username nor the password appears in the log
#### Scenario: Form body stays out of the log
- **GIVEN** a form-encoded POST with a username and a password
- **WHEN** the gateway routes it
- **THEN** no field name or value from the body appears in the log
#### Scenario: Empty body is still routed
- **GIVEN** a POST with no body
- **WHEN** the gateway routes it
- **THEN** the request is logged and reaches the downstream service with no body
#### Scenario: Skip-listed path is not logged
- **WHEN** a request to `/auth/authenticate` passes through the gateway
- **THEN** nothing about it is written to the request log
### Requirement: Credentials in headers and paths are masked
The gateway SHALL mask the values of credential headers (Authorization, Proxy-Authorization, api-key, x-api-key, Cookie, Set-Cookie, X-XSRF-TOKEN, X-CSRF-TOKEN) and any JWT-shaped path segment in the request log. Header names and other header values MUST stay readable. The query string MUST NOT be logged.
#### Scenario: Authorization and api-key are masked
- **GIVEN** a request with an Authorization bearer token, an api-key and an Accept header
- **WHEN** the gateway logs it
- **THEN** the token and the key do not appear in the log
- **AND** the Accept header value does
#### Scenario: JWT in the path is masked
- **WHEN** a request to `/auth/findUserByToken/M/<jwt>` is logged
- **THEN** the log shows `/auth/findUserByToken/M/***`
#### Scenario: Search term in the query string is not logged
- **WHEN** a GET with the query string `?q=aisyah` is logged
- **THEN** the log shows the path without `aisyah`
@@ -0,0 +1,24 @@
# Tasks
Design: `design.md`. One serial task: the filter and its redactor change together.
## 1. Gateway
- [ ] 1.1 Stop logging request bodies (design decisions 1 to 3).
Tests first, in `RequestBodyLoggerFilterTest`:
- a lead update PUT (name, mobile, email, notes): none of the values in the log, method and path present, downstream body unchanged;
- customer login, password change and form login: no body field name or value in the log, downstream body unchanged (rewrites the three masked-body tests);
- an empty POST is logged and forwarded (rewrites `emptyBody`);
- a GET with `?q=aisyah`: the term is not in the log;
- header and JWT-path masking and the skip list keep their existing tests unchanged.
Run them red, then change the filter to log method, masked path and masked headers for every method without reading the body. Delete `LogRedactor.body` and everything only it uses, with the eight body-only `LogRedactorTest` cases named in design decision 2.
Live check: rebuild the gateway, capture and update a made-up lead through the portal, and confirm with `docker compose logs api-gateway` that the lead's name, mobile and email are absent while the request lines are present.
- Scope: `solvway-api-gateway/src/**/filter/RequestBodyLoggerFilter*`, `solvway-api-gateway/src/**/filter/LogRedactor*`
- Verify: `mvn -T 1C -B -q -pl solvway-api-gateway -am verify`.
## Workflow follow-up
- Whole-branch review, push, PR to main and merge, then archive on its own branch.