Skip to content

Support CORS credentials (cookies) via env var#6029

Open
jhead wants to merge 6 commits intomainfrom
feat/cors-creds
Open

Support CORS credentials (cookies) via env var#6029
jhead wants to merge 6 commits intomainfrom
feat/cors-creds

Conversation

@jhead
Copy link
Collaborator

@jhead jhead commented Mar 20, 2026

Adds support for enabling Access-Control-Allow-Credentials via a new CORS_ALLOW_CREDENTIALS environment variable. This is useful when running Flowise behind an authenticating proxy that requires cookies, etc.

Removes an existing middleware that attempted to enable this feature but never worked because the cors() middleware always intercepted and responded to the preflight requests first, so instead I've moved the credentials config to the main cors middleware.

Env var logic defaults to false.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances Flowise's ability to handle Cross-Origin Resource Sharing (CORS) credentials by introducing a dedicated environment variable. This change resolves an issue where an existing custom middleware failed to properly enable credential support, leading to improved compatibility with authenticating proxies. The core modification involves streamlining the CORS configuration to correctly apply credential settings.

Highlights

  • CORS Credentials Support: Introduced support for enabling Access-Control-Allow-Credentials via a new CORS_ALLOW_CREDENTIALS environment variable, allowing Flowise to function correctly behind authenticating proxies that require cookies.
  • Middleware Refactoring: Removed a previously ineffective middleware that attempted to set Access-Control-Allow-Credentials, as it was being bypassed by the main cors() middleware.
  • CORS Configuration Integration: Integrated the credentials configuration directly into the primary CORS middleware, ensuring proper handling of preflight requests and credential forwarding.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly implements support for CORS credentials by adding a CORS_ALLOW_CREDENTIALS environment variable. The change properly moves the credentials configuration into the main cors middleware options, which is the correct approach, and removes the previous, ineffective middleware. The implementation is sound. The suggestion to improve type safety in the getCorsOptions function by replacing any types with specific types from the cors package has been retained, as it enhances maintainability and aligns with general good practices.

Comment on lines 45 to 46
export function getCorsOptions(): any {
return (req: any, callback: (err: Error | null, options?: any) => void) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve type safety and maintainability, it's best to avoid using any. You can use specific types from the cors package. Using import('cors').CorsOptionsDelegate and import('cors').CorsOptions allows for type-safe code without needing to add a new import statement at the top of the file. The Request type is already available from the existing express import.

Suggested change
export function getCorsOptions(): any {
return (req: any, callback: (err: Error | null, options?: any) => void) => {
export function getCorsOptions(): import('cors').CorsOptionsDelegate {
return (req: Request, callback: (err: Error | null, options?: import('cors').CorsOptions) => void) => {

// Add the sanitizeMiddleware to guard against XSS
this.app.use(sanitizeMiddleware)

this.app.use((req, res, next) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the approach in this PR in general (better controls with env var and the change is made at the precise area corsOptions), just wondering if anything would be impacted with the removal of this block

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removed middleware was only ever partially effective. For any request that triggers a preflight (POST with application/json, custom headers like content-type/sentry-trace) — which is the vast majority of Flowise UI traffic — it never worked at all, because cors() intercepts OPTIONS and ends the response before the manual header middleware ran. The header only reached the client for "simple" requests (GET/HEAD, or POST with form-encoded/plain-text bodies), which is a narrow slice that doesn't cover authenticated API flows from what I can tell.

In practice, any integration that needed credentialed cross-origin access to non-simple requests was already broken. Defaulting to false and requiring explicit opt-in via CORS_ALLOW_CREDENTIALS=true is a stricter, more intentional posture with hopefully negligible regression for existing users.

But I'm open to feedback from others if anyone disagrees.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this affect users that have embedded chatbot on their website? https://docs.flowiseai.com/using-flowise/embed#cors

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it probably will, i.e. users need to set the env var to true going forward.

can I suggest that I open a PR to update the documentation?

defaulting to false seems safer because not all Flowise users will be using the embedded chat? so it seems safer to assume we don't want credentials to be passed cross-origin.

I'm open to other POVs though.

@jhead jhead force-pushed the feat/cors-creds branch from 3235cc7 to e3f1604 Compare March 20, 2026 23:33
############################################################################################################

# NUMBER_OF_PROXIES= 1
# CORS_ALLOW_CREDENTIALS=false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be great if a PR could also be added to updated this documentation: https://github.com/FlowiseAI/FlowiseDocs/blob/main/en/configuration/environment-variables.md?plain=1#L181-L190

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.

5 participants