CORS preflight OPTIONS request to API returns 404 #2752

Closed
opened 2025-11-02 04:46:43 -06:00 by GiteaMirror · 10 comments
Owner

Originally created by @salcedo on GitHub (Jan 14, 2019).

  • Gitea version (or commit ref): 1.6.1
  • Git version: 2.20.1
  • Operating system: OpenBSD 6.4
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

I'm working on a project that will make some requests to Gitea's API. As my project is on a different origin, my browser sends a CORS preflight (an OPTIONS request).

Gitea doesn't handle an OPTIONS request, and returns 404.

How to fix?

Works:

curl -X GET https://git.example.com/api/v1/repos/search

Returns 404:

curl -X OPTIONS https://git.example.com/api/v1/repos/search

Screenshots

Originally created by @salcedo on GitHub (Jan 14, 2019). <!-- 1. Please speak English, this is the language all of us can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/NsatcWJ) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): 1.6.1 - Git version: 2.20.1 - Operating system: OpenBSD 6.4 - Database (use `[x]`): - [x] PostgreSQL - [ ] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: ## Description I'm working on a project that will make some requests to Gitea's API. As my project is on a different origin, my browser sends a CORS preflight (an OPTIONS request). Gitea doesn't handle an OPTIONS request, and returns 404. How to fix? ### Works: ``` curl -X GET https://git.example.com/api/v1/repos/search ``` ### Returns 404: ``` curl -X OPTIONS https://git.example.com/api/v1/repos/search ``` ## Screenshots <!-- **If this issue involves the Web Interface, please include a screenshot** -->
GiteaMirror added the issue/confirmedtype/enhancement labels 2025-11-02 04:46:43 -06:00
Author
Owner

@techknowlogick commented on GitHub (Jan 14, 2019):

Closed as duplicate of #5700

There is a PR in works to resolve this

@techknowlogick commented on GitHub (Jan 14, 2019): Closed as duplicate of #5700 There is a PR in works to resolve this
Author
Owner

@JuhoHeiskanen commented on GitHub (Jan 23, 2019):

This issue is technically not a duplicate since #5700 deals with the git smart http protocol, not the Gitea API. Pull #5719 that closed the "duplicate" issue does not resolve this one.

@JuhoHeiskanen commented on GitHub (Jan 23, 2019): This issue is technically not a duplicate since #5700 deals with the git smart http protocol, not the Gitea API. Pull #5719 that closed the "duplicate" issue does not resolve this one.
Author
Owner

@techknowlogick commented on GitHub (Jan 23, 2019):

Access-Control-Allow-Origin header And OPTIONS method response were implemented with that ticket the users purpose may have been for different purposes but they indeed accomplished the same goal

@techknowlogick commented on GitHub (Jan 23, 2019): Access-Control-Allow-Origin header And OPTIONS method response were implemented with that ticket the users purpose may have been for different purposes but they indeed accomplished the same goal
Author
Owner

@JuhoHeiskanen commented on GitHub (Jan 23, 2019):

As far as I can tell, the Gitea API is unaffected by that change. The change does not seem to affect the /api/v1/repos/search endpoint.

@JuhoHeiskanen commented on GitHub (Jan 23, 2019): As far as I can tell, the Gitea API is unaffected by that change. The change does not seem to affect the `/api/v1/repos/search` endpoint.
Author
Owner

@JuhoHeiskanen commented on GitHub (Jan 23, 2019):

To be more clear, the pull did not implement CORS header support for the API, but it did implement support for them in git-over-http.

@JuhoHeiskanen commented on GitHub (Jan 23, 2019): To be more clear, the pull did not implement CORS header support for the API, but it did implement support for them in git-over-http.
Author
Owner

@techknowlogick commented on GitHub (Jan 23, 2019):

That’s helpful information. Thanks :)

@techknowlogick commented on GitHub (Jan 23, 2019): That’s helpful information. Thanks :)
Author
Owner

@FallingSnow commented on GitHub (Jan 31, 2019):

It seems that Gitea doesn't add cors headers to non-option requests either. Cors headers are required on both preflight OPTION requests as well as the following intended requests.

@FallingSnow commented on GitHub (Jan 31, 2019): It seems that Gitea doesn't add cors headers to non-option requests either. Cors headers are required on both preflight `OPTION` requests as well as the following intended requests.
Author
Owner

@stale[bot] commented on GitHub (Apr 1, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Apr 1, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Author
Owner

@klappy commented on GitHub (Apr 16, 2019):

Has anybody made progress or found a functional work around for this issue?

@klappy commented on GitHub (Apr 16, 2019): Has anybody made progress or found a functional work around for this issue?
Author
Owner

@techknowlogick commented on GitHub (Apr 16, 2019):

Current workaround would be to use a reverse proxy that intercepts the request needed and returns the appropriate response.

There is a pending PR for this, however it is awaiting updates from contributor.

@techknowlogick commented on GitHub (Apr 16, 2019): Current workaround would be to use a reverse proxy that intercepts the request needed and returns the appropriate response. There is a pending PR for this, however it is awaiting updates from contributor.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#2752