Merged
Conversation
93582c2 to
8b1c823
Compare
Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
8b1c823 to
99285bc
Compare
- Add ge=1 validation to TokenCreateRequest.expires_in_days schema - Add guard in _generate_token to reject expires_at in the past - Use math.ceil() and max(1, ...) to ensure exp is always set for sub-minute expirations (prevents rounding to 0) - Mark --secret and --algo CLI args as deprecated (always uses config) - Add tests for past expiry rejection and ceiling behavior This fixes a security regression where negative/zero expires_in_days could create permanent tokens instead of expired ones. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
The --secret and --algo CLI parameters now work as optional overrides: - When provided, they override the configuration values - When not provided, JWT_SECRET_KEY and JWT_ALGORITHM from config are used This preserves backward compatibility while still defaulting to configuration-based signing for consistency. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Prevent invalid token generation by requiring --secret when --algo is provided. Using --algo alone would mix config-based keys with a different algorithm, potentially producing tokens that fail validation. Also fixes stale docstring that still referenced DEFAULT_SECRET/DEFAULT_ALGO instead of the new empty-string defaults with config fallback. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Member
Changes Made During ReviewThis PR has been rebased on main and enhanced with the following fixes: 1. Security Fix: Prevent Non-Expiring Tokens from Invalid
|
crivetimihai
approved these changes
Jan 24, 2026
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
* update jwt cli with more inputs Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * fix: prevent non-expiring tokens from invalid expires_in_days - Add ge=1 validation to TokenCreateRequest.expires_in_days schema - Add guard in _generate_token to reject expires_at in the past - Use math.ceil() and max(1, ...) to ensure exp is always set for sub-minute expirations (prevents rounding to 0) - Mark --secret and --algo CLI args as deprecated (always uses config) - Add tests for past expiry rejection and ceiling behavior This fixes a security regression where negative/zero expires_in_days could create permanent tokens instead of expired ones. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: restore --secret and --algo CLI options The --secret and --algo CLI parameters now work as optional overrides: - When provided, they override the configuration values - When not provided, JWT_SECRET_KEY and JWT_ALGORITHM from config are used This preserves backward compatibility while still defaulting to configuration-based signing for consistency. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: require --secret when --algo is specified Prevent invalid token generation by requiring --secret when --algo is provided. Using --algo alone would mix config-based keys with a different algorithm, potentially producing tokens that fail validation. Also fixes stale docstring that still referenced DEFAULT_SECRET/DEFAULT_ALGO instead of the new empty-string defaults with config fallback. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🐛 Bug-fix PR
Closes #2261
📌 Summary
Unifies JWT token creation between CLI and API paths to produce consistent token formats with rich claims support.
Changes
Core Implementation
Enhanced
_create_jwt_token()(mcpgateway/utils/create_jwt_token.py)user_data,teams,namespaces,scopesSimplified
token_catalog_service._generate_token()(mcpgateway/services/token_catalog_service.py)create_jwt_token()with structured dataCLI Enhancement
--admin: Mark user as admin--teams: Comma-separated team IDs--scopes: JSON scopes object--full-name: User's full nameDocumentation
Tests
Example Usage
Before (Simple Token)
After (Rich Admin Token)
Token now includes:
user: {email, full_name, is_admin: true, auth_provider: 'cli'}teams: ['team-123', 'team-456']namespaces: ['user:admin@example.com', 'public', 'team:team-123', 'team:team-456']scopes: {...}(when provided)Security Impact
✅ No new vulnerabilities - CLI already has JWT_SECRET_KEY and can create any token. This change makes the CLI more capable within its existing trust boundary.
✅ Runtime protection maintained - Token scoping middleware validates team membership at request time regardless of how token was created.
✅ Clear documentation - Security warnings prominently displayed in CLI output and all documentation.
Breaking Changes
None - Simple tokens without rich claims continue to work exactly as before. Backward compatible.
🧪 Verification
make lintmake test📐 MCP Compliance (if relevant)
✅ Checklist
make black isort pre-commit)