Fix Access-Control-Expose-Headers for Flask#2329
Fix Access-Control-Expose-Headers for Flask#2329tomkralidis merged 3 commits intogeopython:masterfrom
Access-Control-Expose-Headers for Flask#2329Conversation
| try: | ||
| from flask_cors import CORS | ||
| CORS(APP, CORS_EXPOSE_HEADERS=['*']) | ||
| CORS(APP, expose_headers='*') |
There was a problem hiding this comment.
I renamed this argument here since expose_headers has explicit documentation in the flask cors docs as
:param expose_headers:
The header or list which are safe to expose to the API of a CORS API
specification.
Default : None
It seems you are intended to be able to use CORS_EXPOSE_HEADERS in some way but I was not able to get this to work.
It seems like this header is special in some way and the corresponding header only gets set if expose_headers is in the kwargs, not the uppercase CORS_EXPOSE_HEADERS version of it.
https://github.com/corydolphin/flask-cors/blob/main/flask_cors/core.py#L188 I think this might be a bug in the upstream library. Either way, this is highly dynamic it is probably best to use the version of the arg that is specified as an arg and not a dynamic kwarg.
There was a problem hiding this comment.
One other note, I also checked all the other defaults on CORS and all the others seem reasonable to me. So I didn't edit anything else.
| # Ensure that the expose-headers are set regardless of | ||
| # whether apirules are active or not | ||
| assert response.headers["Access-Control-Expose-Headers"] == "*" |
There was a problem hiding this comment.
Happy to move this elsewhere if preferred. Wanted to avoid spinning up a whole new test just for one header check
Overview
It appears that although it was intended to be set, the header
Access-Control-Expose-Headersis not being set for Flask.If
Access-Control-Expose-Headers: *is not set, then browser clients will not be able to read headers in http responses. This prevents JS clients from accessing returned urls in the OGC API Process responses since the url is in the headers.It seems like this was intended to be set, but
flask_corsisn't using the argument that is currently being supplied.Related Issue / discussion
N/A
Additional information
If you try to fetch the headers from the demo pygeoapi site which I presume is running flask, you can see that
Access-Control-Expose-Headersis missing.If you try to fetch a pygeoapi server like my own that includes this change, the headers for
access-control-expose-headers: *are set as expectedDependency policy (RFC2)
Updates to public demo
Contributions and licensing
(as per https://github.com/geopython/pygeoapi/blob/master/CONTRIBUTING.md#contributions-and-licensing)