mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:47:46 +00:00
Browser+Ladybird+LibWeb: Prevent infinite growth of content filters
We never clear content filters on either end of the Browser-WebContent IPC connection. So when the filters change, we re-append all filters to the Vector holding them. This incidentally makes it impossible to remove a filter. Change both sides to clear their filter lists when receiving a new set of filters.
This commit is contained in:
parent
b0ffb15e13
commit
76ae60da15
5 changed files with 33 additions and 14 deletions
|
@ -33,15 +33,23 @@ bool ContentFilter::is_filtered(const AK::URL& url) const
|
|||
return false;
|
||||
}
|
||||
|
||||
void ContentFilter::add_pattern(DeprecatedString const& pattern)
|
||||
ErrorOr<void> ContentFilter::set_patterns(ReadonlySpan<DeprecatedString> patterns)
|
||||
{
|
||||
StringBuilder builder;
|
||||
if (!pattern.starts_with('*'))
|
||||
builder.append('*');
|
||||
builder.append(pattern);
|
||||
if (!pattern.ends_with('*'))
|
||||
builder.append('*');
|
||||
m_patterns.empend(builder.to_deprecated_string());
|
||||
m_patterns.clear_with_capacity();
|
||||
|
||||
for (auto const& pattern : patterns) {
|
||||
StringBuilder builder;
|
||||
|
||||
if (!pattern.starts_with('*'))
|
||||
TRY(builder.try_append('*'));
|
||||
TRY(builder.try_append(pattern));
|
||||
if (!pattern.ends_with('*'))
|
||||
TRY(builder.try_append('*'));
|
||||
|
||||
TRY(m_patterns.try_empend(builder.to_deprecated_string()));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public:
|
|||
static ContentFilter& the();
|
||||
|
||||
bool is_filtered(const AK::URL&) const;
|
||||
void add_pattern(DeprecatedString const&);
|
||||
ErrorOr<void> set_patterns(ReadonlySpan<DeprecatedString>);
|
||||
|
||||
private:
|
||||
ContentFilter();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue