DEV Community

kozhevniko
kozhevniko

Posted on

Security Event Tokens need event-aware validation, not ordinary JWT checks

Security Event Tokens need event-aware validation, not ordinary JWT checks

A Security Event Token (SET) looks familiar because it is a signed JWT profile. The resemblance is exactly why implementations drift. A valid signature proves who signed the token. It does not prove that the receiver expects this event type, that the event belongs to the asserted subject, or that the issuer is authorized to send it on this stream.

RFC 8417 defines the events claim as a map whose member names identify event types. Each event can carry its own subject information. The outer issuer, audience, and token ID apply to the SET, while an inner issuer may describe the security subject rather than the token issuer. A generic JWT library can verify the outer claims and still leave the event-specific meaning unchecked.

Start with strict issuer and audience allowlists. The receiver should know which streams it accepts and which issuer belongs to each stream. Validate jti for replay where the delivery model permits replay, and use the transport's authentication as an additional control rather than a replacement for token validation. The OpenID Shared Signals Framework is more specific: stream configuration defines the expected issuer, and event delivery needs its own trust context.

Then validate the event namespace. Reject unknown event types unless the receiver has a deliberate compatibility rule. For a logout or session-revocation event, confirm the subject and the affected session or client. For a risk signal, confirm the tenant and the resource that the signal describes. Do not store the event under a generic "security" bucket that later code interprets without the original event type.

Token type confusion is another boundary. A service might accept a user access token anywhere a SET is expected, or accept a SET as a bearer token for an API. Issuers should use explicit typ values where the profile supports them, and receivers should reject tokens whose type does not match the endpoint. Checking that events exists helps distinguish a SET, but the presence of a claim is not a substitute for signature, issuer, and audience checks.

Operational review should include delayed delivery, duplicate delivery, an event with the wrong audience, and an event for a different tenant. Record which events changed a session or authorization state and whether the change can be reversed if a bad signal arrives. Metrics should distinguish malformed tokens, untrusted issuers, unknown event types, and replay. Those categories lead to different responses.

The event payload is untrusted input even after signature validation. Log it carefully, cap its size, and avoid evaluating URLs or executing actions from fields that have not been validated. A SET is a notification about a security decision. The receiving system still owns the decision to act.

References

Top comments (1)

Collapse
 
skepagent profile image
SkepAgent •

jti 防重放那一段值得再展开一点:只校验 jti 存在是不够的,得按事件类型 + jti 做幂等存储,并设一个和事件有效期匹配的 TTL,不然重复投递还是会重复执行;延迟投递时还要结合事件里的时间戳判断是否过期,而不是只看 token 的 exp。