Skip to content

End sessions on password change, restrict SES webhook topics, images-only upload - #18

Merged
op-techy merged 1 commit into
mainfrom
fix/auth-webhook-upload-hardening
Dec 4, 2026
Merged

op-techy merged 1 commit into
mainfrom
fix/auth-webhook-upload-hardening

Conversation

@op-techy

@op-techy op-techy commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Fixes the second batch of audit findings.

Stacked on #17. #17 adds the V2 migration and this PR adds V3. Flyway refuses to run migrations out of order, so merge #17 first; GitHub then retargets this PR to main.

Problems

  1. Sessions survived a password change. A JWT stayed valid until it expired (e.g. 24h), even after a password change or reset. Resetting a password after a suspected compromise didn't lock the attacker out.
  2. The SES webhook accepted any SNS topic. The signature check proves a message came from SNS, but not from our topic. A forged bounce or complaint from someone else's topic could add any address to the suppression list.
  3. Template image upload accepted any file. Files were stored with the content type the client sent, in a public S3 bucket, so HTML and SVG could be hosted there.

Changes

  • Token version:
    • users.token_version is a new column (V3__user_token_version.sql), and every JWT carries it in a ver claim.
    • Change-password, forgot/reset password and admin reset all raise it. JwtAuthFilter then refuses tokens with an older version, which also reduces token parsing from two passes to one.
    • POST /api/auth/change-password still returns message, plus token, user, expiresIn and mustChangePassword. The client should replace its token with the new one; a client that doesn't gets a 401 and logs in again once.
    • Tokens issued before this deploy have no ver, count as version 0, and keep working until they expire.
  • SNS topic allow-list:
    • New setting SES_SNS_TOPIC_ARNS (app.ses.sns-topic-arns), a comma-separated list. Messages from other topics get 403.
    • When it's empty, any topic is accepted, as before, and a warning is logged at startup.
  • Images only:
    • New ImageTypes recognises PNG, JPEG, GIF and WebP from the file's first bytes. SVG is excluded on purpose.
    • TemplateService.uploadImage rejects anything else with 400. It checks that a bucket is configured first, so an unconfigured server still answers 503.
    • S3Service.uploadBytes stores the file under a random name with the detected extension and content type, and Content-Disposition: inline. It replaces uploadFile, which had no other callers.
  • README: documents SES_SNS_TOPIC_ARNS and the SNS setup step.

Deploy notes

  • V3 runs at startup.
  • Set SES_SNS_TOPIC_ARNS to your SES topic ARN(s).
  • Update the frontend to store the token returned by change-password.

Testing

  • ./gradlew test, integrationTest and scaleTest all pass locally.
  • Unit tests:
    • the ver claim, including old tokens without it;
    • the filter refuses a token from before a password change and accepts one from after;
    • change, reset and admin reset each raise the version, and change returns a fresh token;
    • the webhook accepts allowed topics, refuses others with 403, and accepts any topic when the list is empty;
    • image signatures are recognised, and SVG, HTML and mislabelled files are rejected;
    • an image is stored with its real type, whatever name and content type the client sent.
  • Integration tests (Postgres):
    • log in twice, then change the password: both old tokens get 401 and the returned token gets 200;
    • after a reset, the old session gets 401.

…ages-only upload

- Users get a token_version (V3 migration), carried in every JWT as "ver".
  Changing, resetting or admin-resetting a password raises it, and
  JwtAuthFilter refuses tokens from an older version, so a password
  change signs the user out everywhere. change-password returns a fresh
  token next to its message. Tokens issued before this change count as
  version 0 and keep working until they expire.
- /webhooks/ses accepts only the SNS topics in SES_SNS_TOPIC_ARNS (403
  otherwise). A valid signature only proves a message came from SNS, not
  from our topic. Unset, any topic is accepted and a warning is logged.
- Template image uploads must be PNG, JPEG, GIF or WebP, recognised from
  the file's own bytes. The S3 key extension and Content-Type come from
  that, never from the client, so HTML or SVG can't be hosted on the
  public bucket.
@op-techy
op-techy deleted the branch fix/send-compliance December 4, 2026 02:05
@op-techy op-techy closed this Dec 4, 2026
@op-techy op-techy reopened this Dec 4, 2026
@op-techy
op-techy changed the base branch from fix/send-compliance to main December 4, 2026 02:06
@op-techy
op-techy merged commit 866eee7 into main Dec 4, 2026
4 checks passed
@op-techy
op-techy deleted the fix/auth-webhook-upload-hardening branch December 4, 2026 02:10
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