BareProxy Cookie Consent Plugin: A Consent Banner and Cookie Blocking at the Proxy
Status: built, number 13 of 21 in BareProxy’s build order, and out in BareProxy 0.15.0 as consent.wasm on the releases page. Its manual is the README in the code repository.
Under the EU’s ePrivacy rules and the GDPR, a site needs consent before it sets cookies that aren’t strictly necessary: analytics, advertising, embedded third-party content. Most sites handle it with a consent platform loaded as a script, which adds weight to every page and only works as well as the site’s code that is supposed to wait for it.
A proxy sees every cookie a site’s app sets, because each one passes through it in a Set-Cookie header, and it sees every page on its way out. That makes it a good place to enforce the visitor’s choice, as well as ask for it.
What It Does
- A banner with no JavaScript. A visitor who hasn’t chosen gets a small banner at the foot of each HTML page: Accept all, Reject all and Choose, side by side and alike. The buttons are plain links, so a choice works with scripts off, and a settings page lets the visitor tick each category or change their mind later.
- Cookies held back. Until a category is accepted, its cookies are taken out of every response, so they never reach the browser. They’re taken out of requests to the app too, so it can’t read one kept from before.
- Scripts kept out. Most analytics and ad tools set their cookies from JavaScript in the browser, where no proxy sees them. So the plugin keeps their scripts out of the page until there’s consent, by the address they load from: Google Analytics, Meta’s pixel and the rest of the common ones without any config, and any others the config names. Iframes, such as YouTube embeds, work the same way.
- Global Privacy Control respected. A browser that sends the
Sec-GPCsignal counts as having said no, with no banner. - Withdrawal that does something. Taking a category back deletes its cookies in the browser.
- The app knows. Each request to the app carries the choice in an
X-Consentheader, for the cases only the app can handle. - A record. Banners shown, choices made, withdrawals, cookies held back and scripts kept out are counted in
status, and each request’s record says what the plugin did.
Here is a config:
plugin consent /etc/bareproxy/plugins/consent.wasm
config /etc/bareproxy/plugins/consent.conf
body response
site shop.example.com
use consent
route /* -> app
And the plugin’s own, which can be left out to ask about analytics and marketing:
# consent.conf
category analytics Analytics: to count visits
cookies analytics _ga _ga_* _gid
block analytics googletagmanager.com
category videos Videos: YouTube films in the pages
block videos youtube.com
banner We'd like to count visits and show videos from YouTube. Choose what you allow.
privacy /privacy/
Every word of the banner and the settings page comes from the config, so they can be in any language.
Tested in a Real Browser
A script runs the plugin in headless Chromium in front of a page with a tracking script. On the first visit the banner shows and the tracker doesn’t run. After Accept all the browser lands back on the page, the tracker runs and its cookie is set. Unticking the box on the settings page stops the tracker and deletes its cookie. With JavaScript off, Reject all still works, and with Global Privacy Control there’s no banner at all.
That test found a real problem the server tests had missed: a browser that kept a copy of a page from before the visitor chose could get a “not modified” answer and show the old copy. So a page the plugin may change is always fetched whole, and goes out marked private with nothing to check a kept copy against.
Building it also changed BareProxy itself. Go’s proxy flushes a response after every write when it doesn’t know its length, as with most apps that send pages in chunks, and BareProxy used to take that as streaming and let the body past its plugins. From 0.15.0 such a body is held to its end, so the banner reaches those pages too.
What It Can’t Do
A proxy sees the cookies that cross it. One that a script sets in the browser, or that a third party sets from its own domain, never does; the plugin can only keep those scripts out of the page. A site with many third-party tags will still want a review by someone who knows them. Pages that another plugin sends itself, such as Markdown pages, get no banner yet. This page isn’t legal advice, and neither is the plugin.
The whole program is on the plugins page.