Skip to content

Commit

Permalink
url: should validate ipv4 part length
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Apr 29, 2022
1 parent 27ecf1d commit 6a26d2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/node_url.cc
Expand Up @@ -430,6 +430,7 @@ void URLHost::ParseIPv4Host(const char* input, size_t length, bool* is_ipv4) {
pointer++;
}
CHECK_GT(parts, 0);
CHECK_LE(parts, 4);
*is_ipv4 = true;

// If any but the last item in numbers is greater than 255, return failure.
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-whatwg-url-constructor.js
Expand Up @@ -142,3 +142,11 @@ function runURLSearchParamTests() {
runURLSearchParamTests()
runURLConstructorTests()
/* eslint-enable */

const message = {
code: 'ERR_INVALID_URL',
name: 'TypeError',
message: 'Invalid URL',
};

assert_throws(() => new URL('https://256.256.256.256.256'), message);

0 comments on commit 6a26d2e

Please sign in to comment.