Skip to content

Conversation

@alexandre-daubois
Copy link
Member

No description provided.

@alexandre-daubois alexandre-daubois changed the base branch from master to PHP-8.5 September 24, 2025 10:50
@alexandre-daubois alexandre-daubois linked an issue Sep 24, 2025 that may be closed by this pull request
@alexandre-daubois alexandre-daubois force-pushed the uri-port-boundaries branch 2 times, most recently from 95a024c to 62bbdfe Compare September 24, 2025 12:23
@alexandre-daubois alexandre-daubois marked this pull request as ready for review September 24, 2025 13:12
@TimWolla
Copy link
Member

I did not yet read the spec to see if the reported bug is even a bug. But I can say for certain that this this patch is incorrect: Lexbor would be responsible to perform the validation and report the issue. Not PHP.

PS: The NEWS entry is in the wrong location.

@TimWolla TimWolla closed this Sep 24, 2025
@alexandre-daubois
Copy link
Member Author

Should we really do no validation on PHP side about invalid values? Isn't it better to catch errors as early as possible?

Also I'm not sure why this is the wrong location for the news entry?

@kocsismate
Copy link
Member

The spec says the following:

If port is not a 16-bit unsigned integer, port-out-of-range validation error, return failure.

Apparently, the wither call somehow misses the validation. I'll have to debug it why, but the fix must go into the lexbor library indeed. PHP is just a dump wrapper, the logic is better suited in the original upstream library.

@alexandre-daubois
Copy link
Member Author

Alright, I wasn't sure how much it should be "just a wrapper". It's clear now 🙂

@kocsismate
Copy link
Member

As far as I see, the error is only present for negative values around this line: https://github.com/lexbor/lexbor/blob/master/source/lexbor/url/url.c#L1908

I think a negative value check was left out.

@TimWolla
Copy link
Member

Should we really do no validation on PHP side about invalid values?

In the best case, we are just replicating the validation of the upstream library. In the worst case, we are using differing validation, which will lead to security issues. The point of using a library is that it does the heavy lifting for you.

Also I'm not sure why this is the wrong location for the news entry?

Because RC 1 is already tagged.

Apparently, the wither call somehow misses the validation.

There is some validation happening: The port is not actually changed. So the invalid value is not accepted. This might actually be the expected behavior with regard to the specification. See JavaScript:

u = new URL('https://example.com:432');
URL {origin: 'https://example.com:432', protocol: 'https:', username: '', password: '', host: 'example.com:432', …}
u.port
'432'
u.port = '-1';
'-1'
u.port
'432'
u.port = '99999';
'99999'
u.port
'432'
u.port = '99';
'99'
u.port
'99'

@kocsismate
Copy link
Member

I filed an issue upstream with a possible patch: lexbor/lexbor#306

Too large values trigger validation errors, while negative values don't. I think it is only due to an omission, but let's hear Alexander's opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uri\WhatWg\Url Port validation when using withPort

3 participants