-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
My stac-auth-proxy instance is configured with an upstream that handles CORS requests, and is integrated with OPA for filtering.
I'm currently experiencing issues during CORS requests to stac-auth-proxy (which should rely on the upstream response). After breaking down the flow, here’s what I observed when performing an authenticated OPTIONS request to https://stac-auth-proxy/collections/something:
- The OPTIONS request bypasses AuthEnforceMiddleware, as expected, and proceeds to call OPA.
- Depending on what OPA returns, there are three possible scenarios — none of which results in correct CORS handling from my experiments:
- OPA returns void (the response is empty):
- When the OPA policy returns nothing, the Cql2BuildFilterMiddleware raises an error.
- OPA returns null:
- The Cql2BuildFilterMiddleware catches a ValidationError and aborts the request with a 502.
- Subsequently, AddProcessingTimeHeaderMiddleware also raises an error because its call to call_next fails with a RuntimeError: "No response returned".
- OPA returns an always-true expression (for example "1=1")
- stac-auth-proxy forwards the OPTIONS request upstream, which correctly returns an empty response body.
- However, Cql2ValidateResponseBodyMiddleware raises a ParseError because it’s expecting a response body whenever a CQL2 filter is present
- OPA returns void (the response is empty):
From my perspective, unless I’m missing something fundamental, there seem to be several potential improvement points:
- Cql2ValidateResponseBodyMiddleware should not assume a body is always present. If the response body is empty, the middleware should handle it gracefully.
- Cql2BuildFilterMiddleware should not abort the request immediately. Instead, it could raise a proper HTTPException so downstream middleware doesn’t break.
- Cql2BuildFilterMiddleware should allow empty filter results and null values to mean “no filter to apply”. Apart from OPTIONS requests, it could prove useful to avoid applying filters when they are not needed.
What do you think about these potential changes?
alukach
Metadata
Metadata
Assignees
Labels
No labels