Skip to content

feat: lower auth_code_ttl default to 300s and enforce 900s maximum - #4822

Merged
Pratham-Mishra04 merged 1 commit into
devfrom
07-01-feat_clamp_mcp_oauth_auth_token_timeout_to_15minutes
Jul 1, 2026
Merged

feat: lower auth_code_ttl default to 300s and enforce 900s maximum#4822
Pratham-Mishra04 merged 1 commit into
devfrom
07-01-feat_clamp_mcp_oauth_auth_token_timeout_to_15minutes

Conversation

@Pratham-Mishra04

Copy link
Copy Markdown
Collaborator

Summary

Reduces the default OAuth2 authorization code TTL from 600 seconds to 300 seconds and enforces a hard maximum of 900 seconds (15 minutes). This limits the window during which a leaked one-time authorization code could be exploited.

Changes

  • DefaultAuthCodeTTL reduced from 600s to 300s; MaxAuthCodeTTL constant introduced at 900s
  • API handler (/api/config) now rejects auth_code_ttl values exceeding 900s when OAuth or both auth modes are active, returning a 400 error
  • applyClientConfigDefaults clamps any over-max value loaded from config.json or the database (bypassing the API), with a warning log
  • Authorization code issuance clamps the TTL as a final defense-in-depth layer, even if a value was written directly to storage
  • UI updated to reflect the new default (300) and maximum (900), including input validation, placeholder text, and the max attribute on the number input
  • OpenAPI spec and JSON schema updated with maximum: 900, default: 300, and revised descriptions
  • Documentation examples and parameter table updated to reflect the new default and maximum

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

# Verify the cap is enforced at the API layer
curl -X PUT http://localhost:8080/api/config \
  -H "Content-Type: application/json" \
  -d '{"mcp_server_auth_mode":"oauth","oauth2_server_config":{"auth_code_ttl":901}}'
# Expected: 400 Bad Request

# Verify a valid value is accepted
curl -X PUT http://localhost:8080/api/config \
  -H "Content-Type: application/json" \
  -d '{"mcp_server_auth_mode":"oauth","oauth2_server_config":{"auth_code_ttl":300}}'
# Expected: 200 OK

# Run backend tests
go test ./...

# UI
cd ui
pnpm i
pnpm build

Breaking changes

  • Yes
  • No

The default auth_code_ttl drops from 600s to 300s. Any deployment relying on the previous default will now issue shorter-lived authorization codes. Stored values above 900s will be clamped at load time with a warning log and rejected via the API going forward.

Security considerations

Authorization codes are single-use but represent a brief window of exploitability if intercepted. Reducing the default TTL to 5 minutes and capping the maximum at 15 minutes limits the exposure window for leaked codes. The cap is enforced at three layers: API validation, config load, and code issuance, ensuring no path can produce a code with a TTL exceeding 900 seconds.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f49da28f-6a6f-46eb-8e6a-a24d23780d5e

📥 Commits

Reviewing files that changed from the base of the PR and between ead7564 and 4883dcd.

📒 Files selected for processing (11)
  • docs/mcp/gateway-auth.mdx
  • docs/openapi/openapi.json
  • docs/openapi/schemas/management/config.yaml
  • framework/configstore/tables/mcpoauth2server.go
  • transports/bifrost-http/handlers/config.go
  • transports/bifrost-http/handlers/mcpoauth2issuance.go
  • transports/bifrost-http/handlers/mcpoauth2issuance_test.go
  • transports/bifrost-http/lib/config.go
  • transports/bifrost-http/lib/config_test.go
  • transports/config.schema.json
  • ui/app/workspace/config/views/mcpView.tsx
✅ Files skipped from review due to trivial changes (2)
  • docs/openapi/openapi.json
  • docs/mcp/gateway-auth.mdx
🚧 Files skipped from review as they are similar to previous changes (8)
  • transports/config.schema.json
  • transports/bifrost-http/handlers/mcpoauth2issuance.go
  • transports/bifrost-http/lib/config.go
  • transports/bifrost-http/handlers/mcpoauth2issuance_test.go
  • docs/openapi/schemas/management/config.yaml
  • transports/bifrost-http/lib/config_test.go
  • framework/configstore/tables/mcpoauth2server.go
  • ui/app/workspace/config/views/mcpView.tsx

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Updated OAuth authorization code TTL default to 300s (5 minutes) and enforced a 900s (15 minutes) maximum across the UI, API, and runtime behavior.
    • Invalid TTL values are now rejected on configuration save, clamped when issuing authorization codes, and invalid persisted configs now fail fast at startup.
  • Documentation

    • Updated gateway authentication docs and OpenAPI/config schema examples to reflect the new default and maximum.
  • Tests

    • Added coverage for TTL validation, clamping, and startup failure behavior.

Walkthrough

The OAuth2 authorization-code TTL is reduced to 300 seconds and capped at 900 seconds across backend validation, issuance, UI behavior, schemas, and docs.

Changes

OAuth2 Auth Code TTL Default/Max Enforcement

Layer / File(s) Summary
Backend validation and startup checks
framework/configstore/tables/mcpoauth2server.go, transports/bifrost-http/handlers/config.go, transports/bifrost-http/lib/config.go
DefaultAuthCodeTTL is reduced to 300 seconds, updateConfig validates auth mode and rejects over-cap auth_code_ttl before mutation, and LoadConfig fails startup when merged client config exceeds MaxAuthCodeTTL.
Issuance, UI, and validation tests
transports/bifrost-http/handlers/mcpoauth2issuance.go, ui/app/workspace/config/views/mcpView.tsx, transports/bifrost-http/handlers/mcpoauth2issuance_test.go, transports/bifrost-http/lib/config_test.go
handleAuthorize clamps over-cap TTL values, the MCP config UI updates defaults and range checks to 300/900, and tests cover config rejection plus authorization-code expiry resolution.
Schemas and docs
transports/config.schema.json, docs/openapi/openapi.json, docs/openapi/schemas/management/config.yaml, docs/mcp/gateway-auth.mdx
The JSON/YAML/OpenAPI schemas and MCP gateway auth docs now describe auth_code_ttl with a 300-second default, 900-second maximum, and matching example values.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • maximhq/bifrost#4506: Introduces the OAuth2 issuance path that this PR updates for auth-code TTL handling.
  • maximhq/bifrost#4522: Adds the oauth2_server_config.auth_code_ttl contract that this PR revises.
  • maximhq/bifrost#4523: Covers handler-level OAuth2 issuance utilities and tests adjacent to the updated authorize flow.

Suggested reviewers: akshaydeo, danpiths

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: lowering the default TTL and enforcing the new cap.
Description check ✅ Passed The PR description matches the template well and covers summary, changes, testing, breaking changes, and security; only screenshots/issues are missing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 07-01-feat_clamp_mcp_oauth_auth_token_timeout_to_15minutes

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Comment @coderabbitai help to get the list of available commands.

@coderabbitai
coderabbitai Bot requested a review from roroghost17 July 1, 2026 11:50

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@transports/bifrost-http/handlers/config.go`:
- Around line 579-589: Validate auth_code_ttl before any live runtime mutation
in the config update flow, since the current check in the config handler happens
after state-changing calls like DropExcessRequests, MCP manager/in-memory config
updates, and compat plugin reload. Move this validation earlier in the same
handler (using the effectiveOAuth2Config and effectiveAuthMode checks) so an
over-max value fails fast before any in-memory or core state is changed, and
remove the later duplicate auth_code_ttl guard. Ensure the update path remains
rollback-aware so runtime and persistent state stay aligned.

In `@ui/app/workspace/config/views/mcpView.tsx`:
- Around line 233-239: The auth_code_ttl UI validation is stricter than the
config schema and incorrectly blocks valid values from 1 to 59 seconds. Update
the save-time validation in mcpView.tsx (the oauthModeActive/authCodeTTL check)
and the auth_code_ttl input’s min so they match the schema source of truth:
allow 1 through 900 seconds. Keep the existing toast/error flow, but change the
threshold logic to align with the schema and the related input handling in the
same view.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4b772a55-61e5-47a9-a01b-31c363d1ada1

📥 Commits

Reviewing files that changed from the base of the PR and between ac30a53 and b47b7d3.

📒 Files selected for processing (9)
  • docs/mcp/gateway-auth.mdx
  • docs/openapi/openapi.json
  • docs/openapi/schemas/management/config.yaml
  • framework/configstore/tables/mcpoauth2server.go
  • transports/bifrost-http/handlers/config.go
  • transports/bifrost-http/handlers/mcpoauth2issuance.go
  • transports/bifrost-http/lib/config.go
  • transports/config.schema.json
  • ui/app/workspace/config/views/mcpView.tsx

Comment thread transports/bifrost-http/handlers/config.go Outdated
Comment thread ui/app/workspace/config/views/mcpView.tsx
@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

Safe to merge after the upgrade-path discrepancy in validateClientConfig is resolved or documented; all three enforcement layers are implemented correctly and consistently.

The load-time validator hard-fails boot for any stored auth_code_ttl above 900, but the PR's Breaking Changes section tells operators the value will be clamped at load time with a warning log. An operator who previously stored auth_code_ttl=1000 will upgrade and find the server unable to start, with no API path to fix it since the server won't boot. The three-layer enforcement is otherwise correct and internally consistent, and the new tests cover the key branches well.

transports/bifrost-http/lib/config.go — validateClientConfig behavior (hard boot failure) needs to either be corrected to clamp-and-warn or have the Breaking Changes documentation updated to accurately describe the upgrade impact.

Important Files Changed

Filename Overview
transports/bifrost-http/lib/config.go Adds validateClientConfig that hard-fails boot when auth_code_ttl > 900; PR description incorrectly claims graceful clamping — legacy deployments with over-max values cannot start.
transports/bifrost-http/handlers/config.go Moves OAuth2 validation early (before live mutations) and makes auth_code_ttl cap unconditional across all auth modes; removes old headers-mode guard for oauth2_server_config storage.
transports/bifrost-http/handlers/mcpoauth2issuance.go Adds defense-in-depth clamp at code issuance: if TTL exceeds MaxAuthCodeTTL it is silently clamped to 900s before minting the code.
transports/bifrost-http/handlers/mcpoauth2issuance_test.go Adds tests for API-layer rejection and issuance-layer TTL resolution; ConfigHandler tests are placed in the issuance test file rather than a dedicated config handler test, but logic is correct.
transports/bifrost-http/lib/config_test.go Well-structured table-driven tests for validateClientConfig and LoadConfig failure on over-max auth_code_ttl.
framework/configstore/tables/mcpoauth2server.go Introduces MaxAuthCodeTTL = 900 constant and updates DefaultAuthCodeTTL from 600 to 300; comment updated correctly.
ui/app/workspace/config/views/mcpView.tsx Updates default, min, max, placeholder, and validation for auth_code_ttl; change detection correctly updated to ?? 300; data-testid preserved.
transports/config.schema.json Schema updated with maximum: 900, default: 300 in sync with handler and lib changes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["PUT /api/config with auth_code_ttl"] --> B{auth_code_ttl > 900?}
    B -- Yes --> C[400 Bad Request]
    B -- No --> D[Persist to DB]

    E[Server startup: LoadConfig] --> F[loadClientConfig]
    F --> G[validateClientConfig]
    G --> H{auth_code_ttl > 900?}
    H -- Yes --> I["Boot failure — LoadConfig error"]
    H -- No --> J[Server starts]

    K["GET /oauth2/authorize"] --> L[handleAuthorize]
    L --> M{TTL <= 0?}
    M -- Yes --> N["DefaultAuthCodeTTL = 300s"]
    M -- No --> O{TTL > 900?}
    O -- Yes --> P["clamp to MaxAuthCodeTTL = 900s"]
    O -- No --> Q[use configured TTL]
    N --> R[Mint auth code]
    P --> R
    Q --> R
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["PUT /api/config with auth_code_ttl"] --> B{auth_code_ttl > 900?}
    B -- Yes --> C[400 Bad Request]
    B -- No --> D[Persist to DB]

    E[Server startup: LoadConfig] --> F[loadClientConfig]
    F --> G[validateClientConfig]
    G --> H{auth_code_ttl > 900?}
    H -- Yes --> I["Boot failure — LoadConfig error"]
    H -- No --> J[Server starts]

    K["GET /oauth2/authorize"] --> L[handleAuthorize]
    L --> M{TTL <= 0?}
    M -- Yes --> N["DefaultAuthCodeTTL = 300s"]
    M -- No --> O{TTL > 900?}
    O -- Yes --> P["clamp to MaxAuthCodeTTL = 900s"]
    O -- No --> Q[use configured TTL]
    N --> R[Mint auth code]
    P --> R
    Q --> R
Loading

Reviews (3): Last reviewed commit: "feat: clamp mcp oauth auth token timeout..." | Re-trigger Greptile

Comment thread transports/bifrost-http/handlers/config.go Outdated
Comment thread transports/bifrost-http/handlers/config.go Outdated
Comment thread transports/bifrost-http/lib/config.go Outdated
@akshaydeo
akshaydeo requested a review from a team as a code owner July 1, 2026 12:24
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 07-01-feat_clamp_mcp_oauth_auth_token_timeout_to_15minutes branch from b47b7d3 to ead7564 Compare July 1, 2026 16:27
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 1, 2026
Comment thread transports/bifrost-http/handlers/config.go
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 07-01-feat_clamp_mcp_oauth_auth_token_timeout_to_15minutes branch from ead7564 to 4883dcd Compare July 1, 2026 16:38

Pratham-Mishra04 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

Merge activity

  • Jul 1, 4:49 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 1, 4:50 PM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04
Pratham-Mishra04 merged commit a52d180 into dev Jul 1, 2026
14 of 15 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the 07-01-feat_clamp_mcp_oauth_auth_token_timeout_to_15minutes branch July 1, 2026 16:50
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.

2 participants