1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:47:35 +00:00

AK: Serialize URL hosts with 'concept-host-serializer'

In order to follow spec text to achieve this, we need to change the
underlying representation of a host in AK::URL to deserialized format.
Before this, we were parsing the host and then immediately serializing
it again.

Making that change resulted in a whole bunch of fallout.

After this change, callers can access the serialized data through
this concept-host-serializer. The functional end result of this
change is that IPv6 hosts are now correctly serialized to be
surrounded with '[' and ']'.
This commit is contained in:
Shannon Booth 2023-07-27 21:40:41 +12:00 committed by Andreas Kling
parent 768f070b86
commit 8751be09f9
36 changed files with 175 additions and 143 deletions

View file

@ -28,20 +28,29 @@ Trustworthiness is_origin_potentially_trustworthy(HTML::Origin const& origin)
return Trustworthiness::PotentiallyTrustworthy;
// 4. If origins host matches one of the CIDR notations 127.0.0.0/8 or ::1/128 [RFC4632], return "Potentially Trustworthy".
if (auto ipv4_address = IPv4Address::from_string(origin.host()); ipv4_address.has_value() && (ipv4_address->to_u32() & 0xff000000) != 0)
return Trustworthiness::PotentiallyTrustworthy;
if (auto ipv6_address = IPv6Address::from_string(origin.host()); ipv6_address.has_value() && ipv6_address == IPv6Address::loopback())
return Trustworthiness::PotentiallyTrustworthy;
// FIXME: This would be nicer if URL::IPv4Address and URL::IPv6Address were instances of AK::IPv4Address and AK::IPv6Address
if (origin.host().has<AK::URL::IPv4Address>()) {
if ((origin.host().get<AK::URL::IPv4Address>() & 0xff000000) != 0)
return Trustworthiness::PotentiallyTrustworthy;
} else if (origin.host().has<AK::URL::IPv6Address>()) {
auto ipv6_address = origin.host().get<AK::URL::IPv6Address>();
static constexpr AK::URL::IPv6Address loopback { 0, 0, 0, 0, 0, 0, 0, 1 };
if (ipv6_address == loopback)
return Trustworthiness::PotentiallyTrustworthy;
}
// 5. If the user agent conforms to the name resolution rules in [let-localhost-be-localhost] and one of the following is true:
// - origins host is "localhost" or "localhost."
// - origins host ends with ".localhost" or ".localhost."
// then return "Potentially Trustworthy".
// Note: See §5.2 localhost for details on the requirements here.
if (origin.host().is_one_of("localhost"sv, "localhost.")
|| origin.host().ends_with(".localhost"sv)
|| origin.host().ends_with(".localhost."sv)) {
return Trustworthiness::PotentiallyTrustworthy;
if (origin.host().has<String>()) {
auto const& host = origin.host().get<String>();
if (host.is_one_of("localhost"sv, "localhost.")
|| host.ends_with_bytes(".localhost"sv)
|| host.ends_with_bytes(".localhost."sv)) {
return Trustworthiness::PotentiallyTrustworthy;
}
}
// 6. If origins scheme is "file", return "Potentially Trustworthy".