Helmet (Express JS) seems to conflict with the openAPI plugin #1023

Closed
opened 2026-03-13 08:19:13 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @SalonLynk on GitHub (Apr 11, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. add openAPI to the plugins list
  2. add helmet middleware before the .all "/api/auth/*" call

Current vs. Expected behavior

openAPI should still work. Instead I get a blank page.

What version of Better Auth are you using?

latest

Provide environment information

MAcOS

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
import { openAPI} from "better-auth/plugins"

export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
plugins: [
openAPI()
]
});

//backend
app.use(helmet())
app.all("/api/auth/*", toNodeHandler(auth));

Additional context

No response

Originally created by @SalonLynk on GitHub (Apr 11, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. add openAPI to the plugins list 2. add helmet middleware before the .all "/api/auth/*" call ### Current vs. Expected behavior openAPI should still work. Instead I get a blank page. ### What version of Better Auth are you using? latest ### Provide environment information ```bash MAcOS ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" import { openAPI} from "better-auth/plugins" export const auth = betterAuth({ emailAndPassword: { enabled: true }, plugins: [ openAPI() ] }); //backend app.use(helmet()) app.all("/api/auth/*", toNodeHandler(auth)); ``` ### Additional context _No response_
Author
Owner

@Bekacru commented on GitHub (May 7, 2025):

helmet is quite restrictive with loading inline and external scripts. You can do something like this

app.use(
  helmet({
    contentSecurityPolicy: {
      directives: {
        defaultSrc: ["'self'"],
        scriptSrc: ["'self'", "'unsafe-inline'", "https://cdn.jsdelivr.net"],
        styleSrc: ["'self'", "'unsafe-inline'"]
      }
    }
  })
);

or bypass it for /api/auth/reference route

@Bekacru commented on GitHub (May 7, 2025): helmet is quite restrictive with loading inline and external scripts. You can do something like this ```ts app.use( helmet({ contentSecurityPolicy: { directives: { defaultSrc: ["'self'"], scriptSrc: ["'self'", "'unsafe-inline'", "https://cdn.jsdelivr.net"], styleSrc: ["'self'", "'unsafe-inline'"] } } }) ); ``` or bypass it for `/api/auth/reference` route
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1023