Skip to content
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 host parsing for IPv6 URI #1112

Merged
merged 6 commits into from
May 8, 2024
Merged

Fix host parsing for IPv6 URI #1112

merged 6 commits into from
May 8, 2024

Conversation

waahm7
Copy link
Contributor

@waahm7 waahm7 commented May 8, 2024

Issue #, if available:

Description of changes:
If it's IPv6 literal uri like http://[::1]:80/path, the host is not [::1] and is ::1 only.
RFC: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2
urllib3:
image

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 May 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.14%. Comparing base (6236599) to head (e65e3d4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1112      +/-   ##
==========================================
+ Coverage   83.12%   83.14%   +0.01%     
==========================================
  Files          56       56              
  Lines        5755     5760       +5     
==========================================
+ Hits         4784     4789       +5     
  Misses        971      971              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@waahm7 waahm7 changed the title WIP | Fix host parsing for IPv6 URI Fix host parsing for IPv6 URI May 8, 2024
source/uri.c Outdated Show resolved Hide resolved
@@ -509,7 +509,7 @@ static int s_test_uri_ipv6_parse(struct aws_allocator *allocator, void *ctx) {
aws_byte_cursor_from_c_str("[2001:db8:85a3:8d3:1319:8a2e:370:7348%25en0]:443");
ASSERT_BIN_ARRAYS_EQUALS(expected_authority.ptr, expected_authority.len, uri.authority.ptr, uri.authority.len);

struct aws_byte_cursor expected_host = aws_byte_cursor_from_c_str("[2001:db8:85a3:8d3:1319:8a2e:370:7348%25en0]");
Copy link
Contributor

Choose a reason for hiding this comment

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

can you also verify, whether we should be stripping zone idx or not? what do other libs do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is included
image

source/uri.c Outdated
if (!port_delim) {
parser->uri->port = 0;
parser->uri->host_name = authority_parse_csr;
parser->uri->host_name.ptr = authority_parse_csr.ptr + host_name_offset;
parser->uri->host_name.len = authority_parse_csr.len - host_name_length_correction;
Copy link
Contributor

Choose a reason for hiding this comment

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

ugh, not a big fan of manual cursor manipulation?
assign authority_parse_csr to host and then advance and dec len by 1 to remove brackets?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I have updated the code to advance and decrement the length. Initially, I wrote the following code: 1127cad, but later refactored it to reduce code duplication. We can also refactor that version to use 'advance' and 'decrement length.' If you like that version better, I am conflicted between them.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks. i think intent of what you are trying to do is much clearer in the latest version.

one further cleanup we could potentially do is to use aws_byte_cursor_next_split to separate host from port in authority. we can probably even get rid of memchr using that approach. but its a bigger refactoring, so we can do it in future

@waahm7 waahm7 merged commit 24e2396 into main May 8, 2024
51 of 52 checks passed
@waahm7 waahm7 deleted the ecs-ip-enforcement branch May 8, 2024 23:18
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.

None yet

3 participants