Skip to content

fix: check AddWeightedMappings error in updateAccountClaimsWithRefresh - #8473

Open
waterWang wants to merge 1 commit into
nats-io:mainfrom
waterWang:fix/jwt-mapping-error-handling
Open

fix: check AddWeightedMappings error in updateAccountClaimsWithRefresh#8473
waterWang wants to merge 1 commit into
nats-io:mainfrom
waterWang:fix/jwt-mapping-error-handling

Conversation

@waterWang

Copy link
Copy Markdown

Description

When an account JWT is pushed via $SYS.REQ.CLAIMS.UPDATE, updateAccountClaimsWithRefresh calls Account.AddWeightedMappings but discards the returned error. This means:

  1. Duplicate destination subject: jwt.Mapping.Validate has no duplicate check, but AddWeightedMappings returns duplicate entry for %q. The pusher gets 200 "jwt updated" while the mapping stays unchanged.
  2. Invalid transform token: NewSubjectTransform returns an error for invalid transform tokens, which is also silently ignored.

Fix

Capture the error from AddWeightedMappings and log a warning, so the operator is notified when mapping updates fail silently.

References

@waterWang
waterWang requested a review from a team as a code owner August 17, 2026 06:32
@github-actions

Copy link
Copy Markdown

Please review the CONTRIBUTING.md guide as some commits are missing Signed-off-by: in their commit messages.

To correct, please amend the following commits and force-push:

Comment thread server/accounts.go
// This will overwrite existing entries
a.AddWeightedMappings(string(sub), mappings...)
if err := a.AddWeightedMappings(string(sub), mappings...); err != nil {
s.Warnf("Error updating mappings for account %s: %v", a.Name, err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't resolve the issue, as the expected behavior is the following:

A $SYS.REQ.CLAIMS.UPDATE that the server cannot fully apply should not report
success

Instead, is there a way to return an error back to the user?

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.

Account JWT mapping updates that fail AddWeightedMappings are silently discarded, leaving stale or empty mappings

2 participants