Skip to content

Conversation

@graebm
Copy link
Contributor

@graebm graebm commented Dec 24, 2022

Issue:
The websocket client did not fully validate the server's response, as specified in RFC-6455 Section 4.1

The client was doing 1/6 required steps (checking the status-code, but not checking any headers)

Description of changes:
Validate the "Upgrade", "Connection", and "Sec-WebSocket-Accept" headers.

Now we're doing 4/6 required steps. Still need to check "Sec-WebSocket-Extensions" and "Sec-WebSocket-Protocol". That will be in a followup PR.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

codecov-commenter commented Dec 24, 2022

Codecov Report

Base: 79.32% // Head: 79.29% // Decreases project coverage by -0.03% ⚠️

Coverage data is based on head (925775c) compared to base (af5bd44).
Patch coverage: 74.28% of modified lines in pull request are covered.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           on-second-thought     #410      +/-   ##
=====================================================
- Coverage              79.32%   79.29%   -0.04%     
=====================================================
  Files                     27       27              
  Lines                  11786    11841      +55     
=====================================================
+ Hits                    9349     9389      +40     
- Misses                  2437     2452      +15     
Impacted Files Coverage Δ
source/websocket_bootstrap.c 86.59% <71.87%> (-4.19%) ⬇️
source/websocket.c 81.99% <100.00%> (ø)
source/h2_connection.c 82.83% <0.00%> (-0.16%) ⬇️
source/connection_manager.c 88.21% <0.00%> (+0.57%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

/**
* Called repeatedly as payload data arrives.
* Required if `on_incoming_frame_begin` is set.
* Optional.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why I made these 3 callbacks have a weird "all or none" requirement.
Now they're just 3 independent callbacks, you can set any combination you want.
No reason this had to change, it was just weird and I was touching nearby code

return AWS_OP_SUCCESS;
}
if (websocket->on_incoming_frame_payload) {
if (!websocket->on_incoming_frame_payload(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really minor: does it have to be 2 ifs? if (cb && !cb(...)) seems like a common pattern

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the old code was exiting early if no callback was defined and now we are updating window and doing other things. was it a bug in old code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the callbacks in this file are invoked with 2 ifs: one to check whether to invoke the callback, and the next to invoke it and see if it fails

I think it's easier to read

@graebm graebm force-pushed the websocket-validation branch from 3317097 to 72dae35 Compare December 28, 2022 00:08
@graebm graebm changed the base branch from main to better-header-getter December 28, 2022 00:25
Base automatically changed from better-header-getter to main December 28, 2022 00:57
@graebm graebm force-pushed the websocket-validation branch from f9d6eb6 to c8e71eb Compare December 28, 2022 18:04
@graebm graebm changed the base branch from main to on-second-thought December 28, 2022 18:04
Base automatically changed from on-second-thought to main December 28, 2022 23:15
@graebm graebm force-pushed the websocket-validation branch from 925775c to 31a40b6 Compare December 28, 2022 23:18
@graebm graebm enabled auto-merge (squash) December 28, 2022 23:19
@graebm graebm merged commit 44267fe into main Dec 28, 2022
@graebm graebm deleted the websocket-validation branch December 28, 2022 23:30
graebm added a commit that referenced this pull request Dec 28, 2022
This continues #410 ...

This adds the last 2 validation steps specified in [RFC-6455 Section 4.1](https://www.rfc-editor.org/rfc/rfc6455#section-4.1): checking the "Sec-WebSocket-Extensions" and "Sec-WebSocket-Protocol" headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants