[PR #4086] [MERGED] Add preflight OPTIONS handling and update CORS config #11376

Closed
opened 2026-04-12 23:28:57 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/4086
Author: @BruceMacD
Created: 5/1/2024
Status: Merged
Merged: 5/8/2024
Merged by: @BruceMacD

Base: mainHead: brucemacd/auth-cors


📝 Commits (3)

  • 6d3a307 Add preflight OPTIONS handling and update CORS config
  • 0e38ea4 allow auth, content-type, and user-agent headers
  • c2c7d29 Update routes.go

📊 Changes

1 file changed (+6 additions, -0 deletions)

View changed files

📝 server/routes.go (+6 -0)

📄 Description

Couple of tweaks to our CORS configuration and how we handle OPTIONS requests. This update is geared towards making our service more compatible with clients originally designed to work with OpenAI, where sending an Authorization header is common.

Details of Changes

  1. Handling OPTIONS Requests: I added a quick return for OPTIONS requests in our allowedHostsMiddleware. This means we're now ending these preflight requests with a 204 (No Content) status right off the bat.

  2. Updating CORS for Authorization Headers: Since some of the Ollama clients automatically send an Authorization header (because they're set up for OpenAI), I've updated our CORS config to accept these headers. This is needed for making sure these clients can interact with our service without hitting CORS.

Security

Since we're not currently using the Authorization header for our own authentication, allowing this header doesn't open us up to new security risks as long as we don't have auth.

Enabling the OPTIONS method is mainly about letting browsers do their preflight check when they see that Authorization header. It's pretty standard and doesn't pose a direct risk by itself as far as I am aware.

resolves #4001
resolves #3983
resolves https://github.com/ollama/ollama-js/issues/80


🔄 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/ollama/ollama/pull/4086 **Author:** [@BruceMacD](https://github.com/BruceMacD) **Created:** 5/1/2024 **Status:** ✅ Merged **Merged:** 5/8/2024 **Merged by:** [@BruceMacD](https://github.com/BruceMacD) **Base:** `main` ← **Head:** `brucemacd/auth-cors` --- ### 📝 Commits (3) - [`6d3a307`](https://github.com/ollama/ollama/commit/6d3a3072b0a019f3fcdc65de79697ae19934e16d) Add preflight OPTIONS handling and update CORS config - [`0e38ea4`](https://github.com/ollama/ollama/commit/0e38ea4988f6002c76d4c99ea758fbeae64ff153) allow auth, content-type, and user-agent headers - [`c2c7d29`](https://github.com/ollama/ollama/commit/c2c7d2938545eefccb9b448044e54a1ea63f3032) Update routes.go ### 📊 Changes **1 file changed** (+6 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `server/routes.go` (+6 -0) </details> ### 📄 Description Couple of tweaks to our CORS configuration and how we handle `OPTIONS` requests. This update is geared towards making our service more compatible with clients originally designed to work with OpenAI, where sending an `Authorization` header is common. #### Details of Changes 1. **Handling OPTIONS Requests**: I added a quick return for `OPTIONS` requests in our `allowedHostsMiddleware`. This means we're now ending these preflight requests with a 204 (No Content) status right off the bat. 2. **Updating CORS for Authorization Headers**: Since some of the Ollama clients automatically send an `Authorization` header (because they're set up for OpenAI), I've updated our CORS config to accept these headers. This is needed for making sure these clients can interact with our service without hitting CORS. #### Security Since we're not currently using the `Authorization` header for our own authentication, allowing this header doesn't open us up to new security risks as long as we don't have auth. Enabling the `OPTIONS` method is mainly about letting browsers do their preflight check when they see that `Authorization` header. It's pretty standard and doesn't pose a direct risk by itself as far as I am aware. resolves #4001 resolves #3983 resolves https://github.com/ollama/ollama-js/issues/80 --- <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-12 23:28:57 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#11376