Skip to content

Conversation

@tariqksoliman
Copy link
Member

Closes #751

With Claude (bedrock)

Fix API Token Visibility Security Issue (#751)

Description

This PR addresses a critical security vulnerability where regular admins could
view and potentially misuse API tokens created by other admins, including
SuperAdmins. This undermined the tailored permission system by allowing admins
to bypass their restricted permissions using other admins' tokens.

Changes Made

/api/longtermtoken/get endpoint

  • Added permission-based filtering to restrict token visibility
  • SuperAdmins (permission "111") continue to see all tokens
  • Regular Admins (permission "110") now only see tokens they created
  • Uses Sequelize's replacements functionality for SQL injection protection

/api/longtermtoken/clear endpoint

  • Added ownership validation before token deletion
  • SuperAdmins can delete any token
  • Regular Admins can only delete their own tokens
  • Returns appropriate error messages for unauthorized deletion attempts

Technical Details

  • Modified API/Backend/LongTermToken/routes/longtermtokens.js
  • Leverages session data (req.session.permission and req.session.uid) for access
    control
  • Uses parameterized queries with Sequelize replacements to prevent SQL
    injection
  • Properly handles edge cases (e.g., userId could be 0)

Testing

  • Verify SuperAdmins can see all API tokens
  • Verify Regular Admins only see their own tokens
  • Verify Regular Admins cannot delete other users' tokens
  • Verify SuperAdmins can delete any token

Security Impact

This fix ensures that admins with restricted permissions cannot circumvent their
access limitations by using API tokens from other admins, maintaining the
integrity of the permission system.

@tariqksoliman tariqksoliman self-assigned this Sep 11, 2025
@tariqksoliman tariqksoliman added the bug Something isn't working label Sep 11, 2025
@tariqksoliman tariqksoliman merged commit 9535695 into development Sep 11, 2025
1 check passed
@github-project-automation github-project-automation bot moved this to Done in MMGIS Sep 11, 2025
@tariqksoliman tariqksoliman deleted the ts-751 branch September 11, 2025 21:13
@sonarqubecloud
Copy link

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

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: API Tokens are Visible to all Admins Types

2 participants