Skip to content

fix(security): add 5-second execution timeout for custom access token scripts#571

Merged
lakhansamani merged 1 commit intomainfrom
fix/custom-script-sandbox-timeout
Apr 5, 2026
Merged

fix(security): add 5-second execution timeout for custom access token scripts#571
lakhansamani merged 1 commit intomainfrom
fix/custom-script-sandbox-timeout

Conversation

@lakhansamani
Copy link
Copy Markdown
Contributor

Summary

  • Add 5-second execution timeout to the Otto JS VM used for custom access token scripts
  • Prevents DoS via infinite loops or CPU-intensive scripts set by admins
  • Extracted shared runCustomAccessTokenScript helper used by both CreateAccessToken and CreateIDToken
  • Uses vm.Interrupt channel with a goroutine timer; done channel prevents goroutine leaks
  • On timeout, custom claims are skipped gracefully (logged as error) rather than crashing

Files Changed

  • internal/token/auth_token.go — extracted helper with timeout mechanism

Test plan

  • make test-sqlite passes (no regressions)
  • Verify custom access token scripts still execute normally
  • Verify scripts exceeding 5 seconds are terminated gracefully

… scripts

The CustomAccessTokenScript executed in Otto JS VM had no timeout,
allowing malicious or buggy scripts (e.g., infinite loops) to cause
CPU exhaustion / DoS. This adds a 5-second timeout using Otto's
vm.Interrupt channel, with proper goroutine cleanup to prevent leaks.
Both call sites (CreateAccessToken and CreateIDToken) are consolidated
into a single runCustomAccessTokenScript helper method.
@lakhansamani lakhansamani merged commit 8084920 into main Apr 5, 2026
@lakhansamani lakhansamani deleted the fix/custom-script-sandbox-timeout branch April 5, 2026 02:10
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.

1 participant