[PR #5751] feat(plugin-openapi): Allow passing nonce for CSP #14446

Closed
opened 2026-04-13 09:28:44 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5751

State: closed
Merged: Yes


This PR introduces a new nonce option to the openAPI plugin configuration.

When a nonce is provided, it is automatically added as an attribute to the two executable script tags (the inline configuration and the external @scalar/api-reference script) on the API reference page.

This allows the plugin to function correctly under a strict Content Security Policy (CSP) that requires nonces for all scripts.

Changes:

  • Added nonce?: string to OpenAPIOptions in index.ts.
  • Applied the nonce attribute to the two executable <script> tags in getHTML.
  • Updated docs/plugins/open-api.mdx to include the new nonce option.

Fixes #5744


Summary by cubic

Adds a nonce option to the openAPI plugin to support strict CSP by attaching the nonce to executable scripts on the API reference page. This ensures both the inline config and the external @scalar/api-reference script run under CSP.

  • New Features
    • Added nonce?: string to OpenAPIOptions.
    • Injected nonce into the inline config script and the external @scalar/api-reference script via getHTML.
    • Updated plugin docs to document the new nonce option.

Written for commit 4a6027fd6b. Summary will update automatically on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5751 **State:** closed **Merged:** Yes --- This PR introduces a new `nonce` option to the `openAPI` plugin configuration. When a `nonce` is provided, it is automatically added as an attribute to the two executable script tags (the inline configuration and the external `@scalar/api-reference` script) on the API reference page. This allows the plugin to function correctly under a strict Content Security Policy (CSP) that requires nonces for all scripts. **Changes:** * Added `nonce?: string` to `OpenAPIOptions` in `index.ts`. * Applied the `nonce` attribute to the two executable `<script>` tags in `getHTML`. * Updated `docs/plugins/open-api.mdx` to include the new `nonce` option. Fixes #5744 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds a nonce option to the openAPI plugin to support strict CSP by attaching the nonce to executable scripts on the API reference page. This ensures both the inline config and the external @scalar/api-reference script run under CSP. - **New Features** - Added `nonce?: string` to `OpenAPIOptions`. - Injected `nonce` into the inline config script and the external `@scalar/api-reference` script via `getHTML`. - Updated plugin docs to document the new `nonce` option. <sup>Written for commit 4a6027fd6beeddaeea54cbc1e169767caddfa49a. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 09:28:44 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#14446