-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix: HTTP response with invalid headers doesn't throw error #28865 #29420
fix: HTTP response with invalid headers doesn't throw error #28865 #29420
Conversation
…o#28865 When receiving the described HTTP response Cypress resets the headers. This would cause the validateHeaderName method from node to be called which would cause an error, since the headers where invalid. Now Crypress verifies all the headers before reseting them, discards invalid ones and sends a warning in the console when debug module is on.
|
@BernardoSousa03 Thanks for the contribution and for adding a test case around the issue! I’ll check in the upcoming sprint to see who is available to review. |
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 think this approach is fine for now, especially considering the method of failure before. I'd like to see a warning logged to console rather than hiding it behind a debug statement, though - it's important that the modification of the headers be obvious, in case the client is expecting malformed headers.
Thank you for your review @cacieprins. I'll get to it as soon as i can! |
Great, thank you @BernardoSousa03 ! Additionally, it may be useful to include validation of the header value, as well, with I recommend taking a look at
This message could read similar to:
|
@cacieprins while trying out the |
The errors package is for displaying errors to the commandline - they won't show in the GUI, but they will be helpful for folks who may run into issues with this in CI. Please use errors.warning, instead of errors.throwErr, because we don't want to fully throw an error when this is encountered :) |
When cutting off invalid headers from the response the user is informed of such headers in the command line
@cacieprins i have added the requested changes, anything else let me know! |
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 looks like there's a ts error in response-middleware.ts
on L#321 - verify by running yarn check-ts
from the root of the project. Other than that, looks good. I'm a little concerned this may invalidate some system test snapshots - can you run those to verify?
Fixed a typescript error where validateHeaderValue was being called with value possibly being undefined. Fixed catching missing error where code is 'ERROR_INVALID_CHAR' and rethrows other errors
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
When receiving the described HTTP response Cypress resets the headers. This would cause the validateHeaderName method from node to be called which would cause an error, since the headers where invalid. Now Crypress verifies all the headers before reseting them, discards invalid ones and sends a warning in the console when debug module is on.
Additional details
The error lead to Cypress throwing errors when it wasn't supposed to
Steps to test
Create a server that responds with invalid headers to a HTTP request
How has the user experience changed?
The tests don't fail anymore and with the debug module on there is a warning that shows the invalid headers
PR Tasks
cypress-documentation
?type definitions
?