mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibIPC: Ensure only valid URLs are passed over IPC
Invalid URLs should be signified by a wrapper class, such as an Optional<URL::URL> in the IPC file. I do not believe that we have anything which currently relies on passing through an invalid URL.
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
#include <LibCore/Socket.h>
|
#include <LibCore/Socket.h>
|
||||||
#include <LibIPC/Decoder.h>
|
#include <LibIPC/Decoder.h>
|
||||||
#include <LibIPC/File.h>
|
#include <LibIPC/File.h>
|
||||||
|
#include <LibURL/Parser.h>
|
||||||
#include <LibURL/URL.h>
|
#include <LibURL/URL.h>
|
||||||
|
|
||||||
namespace IPC {
|
namespace IPC {
|
||||||
@@ -81,13 +82,15 @@ template<>
|
|||||||
ErrorOr<URL::URL> decode(Decoder& decoder)
|
ErrorOr<URL::URL> decode(Decoder& decoder)
|
||||||
{
|
{
|
||||||
auto url_string = TRY(decoder.decode<ByteString>());
|
auto url_string = TRY(decoder.decode<ByteString>());
|
||||||
URL::URL url { url_string };
|
auto url = URL::Parser::basic_parse(url_string);
|
||||||
|
if (!url.has_value())
|
||||||
|
return Error::from_string_view("Failed to parse URL in IPC Decode"sv);
|
||||||
|
|
||||||
bool has_blob_url = TRY(decoder.decode<bool>());
|
bool has_blob_url = TRY(decoder.decode<bool>());
|
||||||
if (!has_blob_url)
|
if (!has_blob_url)
|
||||||
return url;
|
return url.release_value();
|
||||||
|
|
||||||
url.set_blob_url_entry(URL::BlobURLEntry {
|
url->set_blob_url_entry(URL::BlobURLEntry {
|
||||||
.object = URL::BlobURLEntry::Object {
|
.object = URL::BlobURLEntry::Object {
|
||||||
.type = TRY(decoder.decode<String>()),
|
.type = TRY(decoder.decode<String>()),
|
||||||
.data = TRY(decoder.decode<ByteBuffer>()),
|
.data = TRY(decoder.decode<ByteBuffer>()),
|
||||||
@@ -95,7 +98,7 @@ ErrorOr<URL::URL> decode(Decoder& decoder)
|
|||||||
.environment { .origin = TRY(decoder.decode<URL::Origin>()) },
|
.environment { .origin = TRY(decoder.decode<URL::Origin>()) },
|
||||||
});
|
});
|
||||||
|
|
||||||
return url;
|
return url.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|||||||
Reference in New Issue
Block a user