Skip to content

fix: isolate API token from user code scope - #25

Merged
mattzcarey merged 3 commits into
mainfrom
fix/isolate-api-token-from-user-code
Feb 20, 2026
Merged

fix: isolate API token from user code scope#25
mattzcarey merged 3 commits into
mainfrom
fix/isolate-api-token-from-user-code

Conversation

@mattzcarey

Copy link
Copy Markdown
Contributor

Summary

  • User-submitted code previously executed inside evaluate(apiToken), meaning apiToken was in the lexical scope and directly readable (confirmed during security audit)
  • Moved user code execution into a separate private #run() method where apiToken is not in scope
  • The token is captured inside the cloudflare.request() closure and stored via a #private class field, inaccessible to user code
  • Also includes the GraphQL path detection fix (/graphql instead of /client/v4/graphql)

Test plan

  • Verify cloudflare.request() still works (token is properly used for auth)
  • Verify user code cannot access apiTokentypeof apiToken should be 'undefined'
  • Verify this.#cloudflare is not accessible from user code (private field)
  • Verify accountId is still accessible from user code (module-level const)

Move user code execution from evaluate() into a separate private #run()
method. The apiToken parameter is only accessible within evaluate(),
where it gets captured by the cloudflare.request() closure and stored
on a private class field. User code in #run() can access the cloudflare
helper but not the raw token value.
@mattzcarey mattzcarey changed the title security: isolate API token from user code scope fix: isolate API token from user code scope Feb 20, 2026
@mattzcarey
mattzcarey merged commit 8aad3ed into main Feb 20, 2026
1 check passed
@mattzcarey
mattzcarey deleted the fix/isolate-api-token-from-user-code branch February 20, 2026 00:08
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