WebSafe 3.7github.com
|
|
🏠
Skip to content

fix(audit-log): resolve userName/userEmail for JWT and API key auth paths#3262

Merged
waleedlatif1 merged 1 commit intostagingfrom
fix/audit-actor-lookup
Feb 20, 2026
Merged

fix(audit-log): resolve userName/userEmail for JWT and API key auth paths#3262
waleedlatif1 merged 1 commit intostagingfrom
fix/audit-actor-lookup

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Internal JWT and API key auth paths now resolve userName/userEmail via a PK lookup on the user table
  • Previously, only session-based auth populated actor name/email in AuthResult, leaving audit log entries from executor and API key calls without actor info
  • Lookup is fail-safe — returns null on error so auth is never blocked

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
@vercel
Copy link

vercel bot commented Feb 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Feb 20, 2026 0:30am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 20, 2026

Greptile Summary

This PR fixes a gap in audit logging where JWT and API key authentication paths were leaving actorName and actorEmail empty. The solution adds lazy resolution by looking up user details from the database when both fields are undefined.

Key changes:

  • Refactored recordAudit to extract async logic into insertAuditLog helper function
  • Added user table lookup when actorName === undefined && actorEmail === undefined
  • Lookup is fail-safe with try-catch to prevent blocking audit logs on DB errors
  • Added comprehensive test coverage (6 new test cases) for all resolution scenarios

Issues found:

  • The AND condition on line 208 requires both fields to be undefined for lookup. If one field is undefined and the other is set (even to null), no lookup occurs. Consider using OR logic instead.

Confidence Score: 4/5

  • Safe to merge with one logic issue to address
  • The implementation is well-tested and fail-safe, but the AND condition in the lookup logic could miss some edge cases where only one field is undefined
  • apps/sim/lib/audit/log.ts (line 208) - review the lookup condition logic

Important Files Changed

Filename Overview
apps/sim/lib/audit/log.ts Refactored recordAudit to lazily resolve actor name/email from user table when both are undefined; extracted async logic into insertAuditLog function
apps/sim/lib/audit/log.test.ts Added comprehensive test suite for lazy actor resolution covering lookup success, failure, user not found, and skip scenarios; updated existing tests to provide actorName/actorEmail

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[recordAudit called] --> B[insertAuditLog async]
    B --> C{actorName === undefined<br/>AND<br/>actorEmail === undefined?}
    C -->|Yes| D[Query user table<br/>by actorId]
    C -->|No| H[Use provided values]
    D --> E{Query succeeds?}
    E -->|Yes, user found| F[Set actorName & actorEmail<br/>from DB row]
    E -->|Yes, not found| G[Set both to undefined]
    E -->|No, error| G
    F --> I[Insert audit log]
    G --> I
    H --> I
    I --> J{Insert succeeds?}
    J -->|Yes| K[Log debug success]
    J -->|No| L[Log error, never throw]
Loading

Last reviewed commit: f6b626a

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review

1 similar comment
@waleedlatif1
Copy link
Collaborator Author

@cursor review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

bugbot run

@waleedlatif1
Copy link
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Collaborator Author

bugbot run

@waleedlatif1
Copy link
Collaborator Author

@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@waleedlatif1
Copy link
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Collaborator Author

@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1
Copy link
Collaborator Author

bugbot run

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@waleedlatif1 waleedlatif1 merged commit 9ca5254 into staging Feb 20, 2026
6 of 7 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/audit-actor-lookup branch February 20, 2026 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant

Comments