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 a2e19dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/node_url.cc
Expand Up @@ -432,6 +432,11 @@ void URLHost::ParseIPv4Host(const char* input, size_t length, bool* is_ipv4) {
CHECK_GT(parts, 0);
*is_ipv4 = true;

// If parts’s size is greater than 4, validation error, return failure.
if (parts > 4) {
return;
}

// If any but the last item in numbers is greater than 255, return failure.
// If the last item in numbers is greater than or equal to
// 256^(5 - the number of items in numbers), return failure.
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-whatwg-url-constructor.js
Expand Up @@ -5,6 +5,7 @@ if (!common.hasIntl) {
common.skip('missing Intl');
}

const assert = require('assert');
const fixtures = require('../common/fixtures');
const { test, assert_equals, assert_true, assert_throws } =
require('../common/wpt').harness;
Expand Down Expand Up @@ -142,3 +143,5 @@ function runURLSearchParamTests() {
runURLSearchParamTests()
runURLConstructorTests()
/* eslint-enable */

assert.throws(() => new URL('https://256.256.256.256.256'), { code: 'ERR_INVALID_URL' });

0 comments on commit a2e19dd

Please sign in to comment.