Experience
Projects
My Stack
Case studies
Contact me
Open my CV

·6 min read

One parser branch took 215 sites offline in my browser

At eight minutes past midnight on Sep 10, 2026, I committed a fix with a message that reads like a confession: "Procedural cosmetic rules (site#?#sel) were parsed as blocked hosts, taking 215 sites offline." My own ad blocker had been refusing to load some of the biggest sites on the web, and the browser got the blame, not the filter list. This is the story of how a rule I never meant to support became a rule I enforced.

Project
Light Browser
Date
Sep 2026
Stack
C++, Win32, WebView2
Commit
c396f86

What broke

Light Browser blocks ads by loading a filter list at startup. The list is a mix of formats: plain hosts files, EasyList network rules like ||host^, and cosmetic rules that hide page elements. My parser deliberately supports only a strict subset of that. Anything it cannot honor exactly is supposed to be dropped.

The symptom was the worst kind for a browser: whole sites would not load. The commit comment names three of them, chatgpt.com, bing.com and instagram.com, and the commit message counts 215 sites taken offline in total. Nothing on the screen said "blocked by filter". A user would see a site that works everywhere else fail in Light Browser, and conclude the browser is broken. They would be right.

That is what makes filter bugs expensive. A bad rule does not crash anything and it does not log anything loud. It quietly removes a piece of the internet.

What the code showed

The loader reads the list line by line and tries a chain of branches: skip comments, skip exceptions, handle ||host^ rules, handle my own |substring format, and finally treat what is left as a hosts-file entry, either 0.0.0.0 host or a bare host.

The last branch is the dangerous one, because it is the catch-all. It also stripped anything after a #, on the assumption that a # starts a trailing comment. That assumption is fine for a hosts file:

code
0.0.0.0 ads.example.com   # tracker

Now take a procedural cosmetic rule from EasyList-style lists:

code
chatgpt.com#?#div:has(> span.sponsored)

None of my explicit branches matched it. It fell to the bottom, the code erased everything from the #, and what remained was chatgpt.com, a perfectly valid host. The loader added it to the blocked set. A rule that meant "hide this element on that page" became "never connect to that site".

I want to be precise about what I know here. The snippet above is an illustration I wrote to show the shape of the input. The real list lines are not reproduced in the commit. What the commit does record is the mechanism, in a comment I left in the code:

cpp
// Procedural / scriptlet cosmetic rules ("site.com#?#sel", "#$#", "#%#", "#@?#"):
// not supported. They used to fall through to the hosts-file branch below, where
// the text before '#' became a blocked host and took whole sites (chatgpt.com,
// bing.com, instagram.com, ...) offline.

So the root cause was not a typo. It was a missing "no" in a parser whose default answer was "yes". The fall-through branch assumed that every line that reached it was a host.

The fix

The fix landed in c396f86 in Sep 2026, in src/adblock.cpp, and it has three parts.

First, an explicit skip. If a line has a # followed directly by ?, $, % or @, it is one of the cosmetic or scriptlet syntaxes I do not support, so the loader moves on:

cpp
if (size_t hp = line.find('#'); hp != std::string::npos && hp + 1 < line.size() &&
    (line[hp + 1] == '?' || line[hp + 1] == '$' || line[hp + 1] == '%' || line[hp + 1] == '@'))
    continue;

Second, a stricter definition of a comment. In the hosts-file branch a # now only starts a trailing comment when it follows a space or tab. A # glued to the text is some other syntax, so the line is skipped:

cpp
if (hash == 0 || (line[hash - 1] != ' ' && line[hash - 1] != '\t')) continue;

Third, a related over-blocking cause I found in the same pass. Rules like ||host^$third-party had been treated as plain host rules, which blocks the host even when you are visiting it directly. They now go into their own set, tpHosts_, and ShouldBlock takes the page's site as a second argument. A third-party rule only fires when the request host is not the page's site or one of its subdomains:

cpp
bool firstParty = !pageSite.empty() &&
    (host == pageSite || (host.size() > pageSite.size() && host.ends_with(pageSite) &&
     host[host.size() - pageSite.size() - 1] == '.'));
...
if (!firstParty && tpHosts_.find(std::string(h)) != tpHosts_.end()) return true;

The request interceptor in src/services.cpp now reads the page's source from the WebView and passes its site along, so the check runs on every sub-resource request.

beforetext before #aftercontinueFilter linesite.com#?#selectorCosmetic skipnew in c396f86Hosts-file branchcatch-allRule droppedsite still loadsBlocked host setwhole site offline
Figure 1. Before the fix, a cosmetic rule reached the hosts-file branch. After it, the rule is skipped before it can become a host.

The commit also bundled other work: favicons, a per-site ad toggle, and a tab close-button hit-test fix. The ad-blocking change is the part worth reading.

What I would do differently

I would not have a catch-all branch that accepts input by default. The fall-through was a design choice I made for convenience, because hosts files are the easiest format to support, and it meant every future unknown syntax would be silently accepted as a host. A stricter parser would validate that the leftover text looks like a hostname, or that the line looks like a hosts entry, before adding it. The explicit skip fixes four syntaxes. A stricter catch-all would have covered the ones I have not seen yet.

I also had no test that fed the loader a real, messy list and asserted that common sites were not in the blocked set. The commit contains no such test. A cheap guard, a short list of sites that must never be blocked, would have caught this at build time instead of on a user's screen. I did not add one in this commit, so I cannot say it exists.

I would also count the rules the loader skips, by category, and show that number somewhere. "215 lines read as hosts" is a loud signal, and a quiet parser never raises it.

The rule I kept is simple. If I cannot honor a filter rule exactly, I drop it. Skipping is safe. Misreading is not.

Where this fits

This bug is one chapter of a larger project: a small C++ browser on top of the system web engine, with its own blocker, memory manager and installer. If you want the whole picture, including the other bugs that came from running real sites through it, read the full Light Browser case study.

The full story covers the memory, antivirus and update bugs that followed, and how they shaped the shell.

Read the full case study

#cpp#adblock#debugging#parsing

Keep reading

Have a project in mind?