Skip to content

[M15] Redact Authorization JWT and request bodies from logs - #52

Open
bsatrom wants to merge 1 commit into
mainfrom
fix/infra/m15-redact-logs
Open

bsatrom wants to merge 1 commit into
mainfrom
fix/infra/m15-redact-logs

Conversation

@bsatrom

@bsatrom bsatrom commented Jul 2, 2026

Copy link
Copy Markdown
Member

M15 — Redact Authorization JWT and request bodies from CloudWatch logs

Finding: Several handlers ran console.log('...', JSON.stringify(event)) at
entry, writing the full API Gateway event — including the Authorization
bearer JWT and raw request bodies (Wi-Fi SSID/passwords, etc.) — to CloudWatch
(14-day retention).

Affected handlers: api-ingest (120, 136), api-devices (37),
api-config (92), api-commands (117), api-notehub (118),
api-public-device (29).

Fix

  • Added a shared redact() / safeStringify() helper in
    lambda/shared/utils.ts:
    • Recursively masks sensitive header names (authorization, cookie,
      x-api-key, security/session tokens) case-insensitively.
    • Masks sensitive body/field names (password, secret, token,
      *_token, api_key, ssid, wifi, credentials, …).
    • Masks inline Bearer <token> substrings inside string values.
    • Never mutates the input.
  • Replaced the entry-log JSON.stringify(event) calls in all six handlers
    with safeStringify(event).

Tests

  • New lambda/shared/utils.test.ts covers header redaction (both casings),
    body-field redaction, nested/array redaction, inline bearer masking,
    primitive pass-through, and non-mutation.

Verification

  • npm run build — passes (tsc clean).
  • npm test — 464 passed (33 files).

Closes review finding M15

Add a shared redact()/safeStringify() helper in lambda/shared/utils.ts and
apply it to the request-entry console.log(event) calls across api-ingest,
api-devices, api-config, api-commands, api-notehub, and api-public-device.

Previously these handlers logged the full API Gateway event (including the
Authorization bearer JWT and raw request bodies with Wi-Fi SSID/passwords)
to CloudWatch. The helper recursively masks sensitive headers/fields and
inline Bearer tokens without mutating the input. Adds utils.test.ts.

Closes review finding M15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant