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

Closed
opened 2026-04-17 22:40:37 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5751
Author: @GautamBytes
Created: 11/4/2025
Status: Merged
Merged: 11/4/2025
Merged by: @Bekacru

Base: canaryHead: feat/openapi-nonce


📝 Commits (1)

  • 4a6027f feat(plugin-openapi): add nonce support for CSP

📊 Changes

2 files changed (+16 additions, -4 deletions)

View changed files

📝 docs/content/docs/plugins/open-api.mdx (+2 -0)
📝 packages/better-auth/src/plugins/open-api/index.ts (+14 -4)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5751 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 11/4/2025 **Status:** ✅ Merged **Merged:** 11/4/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/openapi-nonce` --- ### 📝 Commits (1) - [`4a6027f`](https://github.com/better-auth/better-auth/commit/4a6027fd6beeddaeea54cbc1e169767caddfa49a) feat(plugin-openapi): add nonce support for CSP ### 📊 Changes **2 files changed** (+16 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/open-api.mdx` (+2 -0) 📝 `packages/better-auth/src/plugins/open-api/index.ts` (+14 -4) </details> ### 📄 Description 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. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 22:40:37 -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#31800