-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solve last CORS issues about duplicated headers #604
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #604 +/- ##
==========================================
+ Coverage 44.17% 44.20% +0.02%
==========================================
Files 55 55
Lines 5023 5022 -1
Branches 595 595
==========================================
+ Hits 2219 2220 +1
+ Misses 2678 2676 -2
Partials 126 126 ☔ View full report in Codecov by Sentry. |
Failed to retrieve llama text: POST 504: 504 Gateway Time-outThe server didn't respond in time. |
I've looked at the changes and don't see any particular problems. Is there a way to check it manually? |
@@ -92,6 +93,7 @@ def get_machine_properties() -> MachineProperties: | |||
) | |||
|
|||
|
|||
@cors_allow_all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the use of this decorator, not just here but in general, since a global cors config was added in supervisor.py?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a custom decorator that handles the CORS using this library: https://github.com/aio-libs/aiohttp-cors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I have read the decorator code, but you realise it add the same cors config that you also added in supervisor.py in your previous PR? Doesn't that seems a bit strange to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is a public endpoint used by the frontend, our frontend or other ones, so the endpoint should accept the same configuration as the other endpoints. As the decorator name says, allow all origins on CORS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed on the team chat, it's missing a lot of information to test the whole CORS information properly but it seems to improve the situation.
Before calling http://localhost:4020/status/check/fastapi from another site was crashing with this error
File "/usr/lib/python3/dist-packages/aiosignal/__init__.py", line 36, in send
await receiver(*args, **kwargs) # type: ignore
File "/home/ubuntu/aleph-venv/lib/python3.10/site-packages/aiohttp_cors/cors_config.py", line 171, in _on_response_prepare
assert hdrs.ACCESS_CONTROL_ALLOW_ORIGIN not in response.headers
AssertionError
Here is an export of the request I had as fetch
await fetch("http://localhost:4020/status/check/fastapi", {
"credentials": "omit",
"headers": {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0",
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"Content-Type": "application/json",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-site"
},
"referrer": "http://localhost:5174/",
"method": "GET",
"mode": "cors"
});
Now it is not.
Yes, it's true, we need some tests to avoid have future CORS issues, you also can create that unit tests. |
If you check the code files changed on that PR, I have removed that hardcoded headers related to CORS on some endpoint that created the issue:
|
I understood your change and have validated that this change works, I meant checking for other potential problems. |
As I have mentioned on the team's chat today:
So I have prevented to have that issue on other parts of the code and ensuring that we have the middleware set on all these endpoints. |
Fix: Solve last CORS errors raised cause by duplication of headers returned.
Fix: Solve last CORS errors raised cause by duplication of headers returned.