mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 18:32:28 -05:00
LibWeb: Add a maximum redirects limit to FrameLoader
This prevents the browser from crashing when trying to load an infinite redirects loop. The chosen limit is based on the fetch specification: "If request's redirect count is twenty, return a network error."
This commit is contained in:
parent
84800a5b4f
commit
ce86026ac6
2 changed files with 10 additions and 0 deletions
|
@ -237,9 +237,16 @@ void FrameLoader::resource_did_load()
|
||||||
// FIXME: Also check HTTP status code before redirecting
|
// FIXME: Also check HTTP status code before redirecting
|
||||||
auto location = resource()->response_headers().get("Location");
|
auto location = resource()->response_headers().get("Location");
|
||||||
if (location.has_value()) {
|
if (location.has_value()) {
|
||||||
|
if (m_redirects_count > maximum_redirects_allowed) {
|
||||||
|
m_redirects_count = 0;
|
||||||
|
load_error_page(url, "Too many redirects");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_redirects_count++;
|
||||||
load(url.complete_url(location.value()), FrameLoader::Type::Navigation);
|
load(url.complete_url(location.value()), FrameLoader::Type::Navigation);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
m_redirects_count = 0;
|
||||||
|
|
||||||
dbgln("I believe this content has MIME type '{}', encoding '{}'", resource()->mime_type(), resource()->encoding());
|
dbgln("I believe this content has MIME type '{}', encoding '{}'", resource()->mime_type(), resource()->encoding());
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
namespace Web {
|
namespace Web {
|
||||||
|
|
||||||
|
constexpr size_t maximum_redirects_allowed = 20;
|
||||||
|
|
||||||
class FrameLoader final
|
class FrameLoader final
|
||||||
: public ResourceClient {
|
: public ResourceClient {
|
||||||
public:
|
public:
|
||||||
|
@ -41,6 +43,7 @@ private:
|
||||||
bool parse_document(DOM::Document&, const ByteBuffer& data);
|
bool parse_document(DOM::Document&, const ByteBuffer& data);
|
||||||
|
|
||||||
Frame& m_frame;
|
Frame& m_frame;
|
||||||
|
size_t m_redirects_count { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue