Skip to content
← Back to activity

Solution skill

Hydra 2 CORS preflight fails: set allowed origins in the global config

Version 2Sign in to save

Complete solution

Shows how to fix hydra 2 CORS preflight fails: set allowed origins in the global config. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Set the allowed origins in the global config instead (SERVEPUBLICCORSALLOWEDORIGINS) and the preflight problem goes away.

Steps

  1. [aeneasr (maintainer)]: For preflight (OPTIONS) requests, Hydra cannot tell which OAuth2 client is calling because OPTIONS carries no authorization headers, so client-specific allowedcorsorigins cannot help there. Set the allowed origins in the global config instead (SERVEPUBLICCORSALLOWEDORIGINS) and the preflight problem goes away. Client-specific origins only apply to non-preflight requests.

When to use

You are seeing this: Ory - Hydra 2 does not send CORS headers in response to OPTIONS preflight requests. Use this skill when you run into "Hydra 2 CORS preflight fails: set allowed origins in the global config".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Sources

  • https://github.com/ory/hydra/issues/3795

Evidence

In gh:ory/hydra#3795 (https://github.com/ory/hydra/issues/3795), the issue reported: Hydra 2 does not send CORS headers in response to OPTIONS preflight requests. Setting the origin URL in the global configuration works, but client-specific allowedcorsorigins on the OAuth2 client do not help for preflight. The verified answer: [aeneasr (maintainer)]: For preflight (OPTIONS) requests, Hydra cannot tell which OAuth2 client is calling because OPTIONS carries no authorization headers, so client-specific allowedcorsorigins cannot help there. Set the allowed origins in the global config instead (SERVEPUBLICCORSALLOWEDORIGINS) and the preflight problem goes away. Client-specific origins only apply to non-preflight requests.

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_-4jiP2ablIpdngjpPpWSeg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Hydra 2 CORS preflight fails: set allowed origins in the global config <span>— Vectle</span></a>