P-10
Prumo
A public political sign-up, printed links that never break, and a database that answers to nothing but the Functions.
client████Outreach front for voters over 60 in a national majoritarian campaign
A mobilization web platform for voters over 60: a sign-up that leads straight to the state's WhatsApp group, trackable links with QR codes, automatic invite rotation when a group fills up, a street action map, a letter generator, and a panel the team runs without deploys. Framework-free HTML and JavaScript on Cloudflare Pages, Postgres on Supabase closed off from the browser, and a security audit whose 9 findings were fixed in tested batches.
- cloudflare
- supabase
- postgres
- rls
- anti-bot
- csp
- security-audit
- lgpd
- vanilla-js
- webhooks
01Overview
Prumo is the web platform for an outreach front inside a national majoritarian election campaign, aimed at people over 60. Visitors arrive through a WhatsApp link, a QR code on a flyer or an ad, sign up, and land straight in their state's WhatsApp group. From there the site gives them tools to bring more people in: printable materials, a large-print personalized letter generator, a map of street actions and a gallery of ready-to-post artwork.
On the other side, the campaign team runs an admin panel to follow sign-ups by state, city and campaign, create trackable links with QR codes, swap WhatsApp group invites when groups fill up, moderate street actions and publish artwork, all without a developer or a deploy.
The site is plain HTML, CSS and JavaScript, with no framework and zero runtime dependencies, served from Cloudflare Pages. The dynamic part is a set of edge functions talking to Postgres on Supabase. It was a team project, built and run in production over eight weeks of campaigning; my share was security (a full audit and the fixes), campaign tracking and the group infrastructure.
02The problem
- A public political form. A page that collects supporters' name, WhatsApp number, email, birth year and city handles data that Brazil's LGPD treats as sensitive (political opinion). It has to hold up against bots, against people trying to pollute the list, and against anyone trying to find out who signed up.
- An audience that is not digital-native. Large type, few steps, no JavaScript where it can be avoided, links that never break.
- Print has no undo. QR codes on flyers and posters point to URLs that must keep working until the campaign ends, even if the target changes or the database goes down.
- WhatsApp groups fill up. Each state has a group with a member cap; once it's full, every link already in circulation has to start pointing to the next one, without anyone editing material.
- Knowing what works. The campaign wanted to know which event, poster or ad brought in each sign-up, and pass that on to its mobilization CRM.
03The solution
- One-screen sign-up with a phone mask, area-code and mobile-digit validation, explicit opt-in, and the privacy policy version stored with each record. On success, the person goes to their state's group.
- Per-state group links (
/grupo-<uf>) for QR codes and word of mouth, redirecting viameta refreshso they work without JavaScript, plus an ads variant (/grupotp-<uf>) that keeps the invite out of the HTML, because the ad platform's validator rejects landing pages containing group links. - Automatic invite rotation. An external monitoring system posts member counts to a webhook; when a group hits its cap, the site puts the next invite in that state's queue live.
- Trackable short links (
/l/<slug>) created in the panel, with QR codes generated on-site, click counts that ignore link-preview bots, and sign-up attribution through UTM parameters. - Street action map: an SVG map of Brazil built from the official IBGE mesh, server-side geocoding of addresses, and a "use my location" button resolved entirely in the browser, so the position never leaves the page.
- Letter generator on
<canvas>(1080 × 1920, type scaled to the largest size that fits), shared through the phone's native share sheet. - Artwork gallery fed from the panel, with direct uploads to Storage and a full-screen viewer.
- Admin panel with KPIs, breakdowns by state, city and campaign, CSV export, UTM links, groups, street actions and the gallery.
- Discoverability:
sitemap.xmlgenerated at build time withlastmodtaken from git, JSON-LD kept consistent across pages, and arobots.txtwith explicit directives for search engines and generative engines.
- Adversarial audit with 9 findings (2 high); 8 fixed in code on the same day, in 5 tested batches.
- The sign-up stopped being an oracle: identical responses for new and repeat numbers, revealing neither who supports nor where they live.
- RLS on every table, zero policies and functions executable only by service_role: the public key can't read or write anything.
- WhatsApp invite rotation handled by a Postgres trigger and race-proofed with a conditional UPDATE.
- Printed QR links never return a 404 or 500: any failure becomes a silent no-store redirect.
- Zero runtime dependencies, 209 tests and 178 lint checks that fail the build when the contract breaks.
04Architecture
Read the diagram as a list (18 components, 20 connections)
Components
- Clients: Supporter 60+<br>(phone, WhatsApp link), Printed QR<br>and ads, Campaign team<br>(/admin), Group monitor<br>(external system)
- Cloudflare Pages: Framework-free static site<br>10 pages · CSP · HSTS<br>build = copy to dist/, _middleware<br>legacy domain → 301, Pages Functions<br>/api/cadastros · /api/acoes · /api/cartas-contato<br>/api/grupos · /api/vouvotar, /api/admin<br>HttpOnly SameSite=Strict cookies<br>allowlist on every request, /api/lotacao<br>secret-signed webhook<br>constant-time comparison, /l/slug · /grupo-uf · /grupotp-uf<br>never 404: silent fallback, Turnstile<br>action + hostname, fail-closed
- Supabase: Postgres<br>RLS on every table, 0 policies<br>functions for service_role only, Rotation trigger<br>active → history, queue → active, Auth<br>email and password, Storage<br>public artwork bucket
Connections
- Supporter 60+<br>(phone, WhatsApp link) → Framework-free static site<br>10 pages · CSP · HSTS<br>build = copy to dist/
- Printed QR<br>and ads → /l/slug · /grupo-uf · /grupotp-uf<br>never 404: silent fallback
- Supporter 60+<br>(phone, WhatsApp link) → Turnstile<br>action + hostname, fail-closed (token)
- Campaign team<br>(/admin) → Turnstile<br>action + hostname, fail-closed (token)
- Framework-free static site<br>10 pages · CSP · HSTS<br>build = copy to dist/ → Pages Functions<br>/api/cadastros · /api/acoes · /api/cartas-contato<br>/api/grupos · /api/vouvotar
- Campaign team<br>(/admin) → /api/admin<br>HttpOnly SameSite=Strict cookies<br>allowlist on every request
- Group monitor<br>(external system) → /api/lotacao<br>secret-signed webhook<br>constant-time comparison
- Pages Functions<br>/api/cadastros · /api/acoes · /api/cartas-contato<br>/api/grupos · /api/vouvotar → Turnstile<br>action + hostname, fail-closed
- /api/admin<br>HttpOnly SameSite=Strict cookies<br>allowlist on every request → Turnstile<br>action + hostname, fail-closed
- Pages Functions<br>/api/cadastros · /api/acoes · /api/cartas-contato<br>/api/grupos · /api/vouvotar → Postgres<br>RLS on every table, 0 policies<br>functions for service_role only (service_role)
- /api/admin<br>HttpOnly SameSite=Strict cookies<br>allowlist on every request → Postgres<br>RLS on every table, 0 policies<br>functions for service_role only (service_role)
- /api/admin<br>HttpOnly SameSite=Strict cookies<br>allowlist on every request → Auth<br>email and password
- /api/admin<br>HttpOnly SameSite=Strict cookies<br>allowlist on every request → Storage<br>public artwork bucket (upload validated by bytes)
- /api/lotacao<br>secret-signed webhook<br>constant-time comparison → Postgres<br>RLS on every table, 0 policies<br>functions for service_role only
- Postgres<br>RLS on every table, 0 policies<br>functions for service_role only → Rotation trigger<br>active → history, queue → active
- /l/slug · /grupo-uf · /grupotp-uf<br>never 404: silent fallback → Postgres<br>RLS on every table, 0 policies<br>functions for service_role only
- /l/slug · /grupo-uf · /grupotp-uf<br>never 404: silent fallback → WhatsApp<br>groups per state
- Pages Functions<br>/api/cadastros · /api/acoes · /api/cartas-contato<br>/api/grupos · /api/vouvotar → Mobilization CRM<br>(waitUntil, off the response path)
- Pages Functions<br>/api/cadastros · /api/acoes · /api/cartas-contato<br>/api/grupos · /api/vouvotar → Nominatim / OSM<br>server-side geocoding
- Framework-free static site<br>10 pages · CSP · HSTS<br>build = copy to dist/ → Storage<br>public artwork bucket (images)
The diagram labels are in Portuguese, as in the codebase.
Every read and write goes through a Pages Function. The Supabase key never reaches the browser, and the database grants nothing to the anon and authenticated roles: if the public key ever leaked, it couldn't read or write a single row.
05Under the hood
- 12 Pages Functions files: 7 API routes, 3 server-rendered page routes (organic per-state group, ads per-state group and the national network entry point), the short link, and a legacy-domain middleware.
/api/adminhandles 25 actions (12 reads, 11 writes, login and logout) through a single router with an explicit allowlist of write methods. - Postgres on Supabase: 10 tables created by the versioned scripts (plus the sign-up table, which predates them and is altered by them), 20 functions and 3 triggers. Every function has
EXECUTErevoked frompublic,anonandauthenticatedand granted only toservice_role; none isSECURITY DEFINER. - Invite rotation lives in the database. Swapping a state's active invite is a single
UPDATEonwhatsapp_grupos.link. A trigger does the rest in the same transaction: it archives the outgoing invite (as "full" or "replaced"), pops the new one off the queue and resets the member count. The panel, SQL loads and automatic rotation all share that one path. A unique index prevents the same invite from sitting in two states' queues, and an invite marked full can never come back. - Attribution without an extra column. A sign-up belongs to a link when all five
utm_*values match. Normalization (lowercase, spaces to hyphens, symbols stripped, 80 characters) lives in one library used by the Function and mirrored in the panel, with a test proving both produce the same value. That's why the database rejects two links with the same combination, and a link with history can no longer change its UTMs. - CRM integration. Each accepted sign-up is sent to the mobilization CRM off the response path (
waitUntil, 8 s timeout): the form never waits for the CRM, and a CRM failure can't undo a sign-up already stored. The campaign reaches the CRM three ways (source, custom fields and a tag) because the team filters in different ways. - Geocoding happens server-side when an action is submitted, with at most three stepped queries (address, neighborhood, city), an identifying
User-Agent, and a check that the result falls inside the city given. If nothing matches, the action is stored without a pin rather than rejected. - CSV export from the panel in batches of 1,000 rows, up to 50,000.
- No framework, no dependencies:
package.jsonhas nodependencies. The build copies files intodist/and generates the sitemap. There are 10 public pages plus the panel. - Accessibility for an older audience: semantic lists (
<ul>/<li>) so screen readers count items, a native<details>menu for policy proposals (works without JS),prefers-reduced-motionhonored, and every image withalt,widthandheight. - Safe rendering in the panel: server data goes in through
textContent/createElement, neverinnerHTML. The QR code library is bundled on-site because the panel's CSP doesn't allow CDNs. - Custom font: the brand typeface shipped without accented characters; a Python script (
fontTools) draws Portuguese diacritics from the font's own shapes and outputs WOFF2 under a distinct family name. - SVG map with the Mercator projection embedded, which lets pins be placed by latitude/longitude and the user's state be found by point-in-polygon, with no API call.
- Cloudflare Pages building with
npm run buildintodist/. Secrets live in the project's encrypted variables, never in the repository (only an.env.examplewith placeholders). _routes.jsonkeeps static assets off the Functions path: images, CSS and JS don't wake the Worker, which cuts billed invocations._headerssets CSP, HSTS and anti-framing on every route, a stricter block for the panel, and caching per asset type (fonts immutable for a year, artwork for a month).- An explicit
404.html: without it, Pages treats the site as an SPA and the dynamic routes stop being called. - Structural lint (
scripts/check.mjs, 178 checks) that fails the build when any part of the contract breaks: a secret referenced in front-end code, CSP drift between_headersand the Worker-rendered page, divergingDisallowlists acrossrobots.txtgroups, the ads route exposing the invite again, a member cap that differs between JS and SQL, an indexable page missing from the sitemap. - Tests: 209 tests across 19 files using
node:testwith a mockedfetch, no dependencies, no network.
06Security
8 attacks considered, 8 defenses in production.
Scripts that flood forms, inflate numbers or sweep the site for openings.
Bots flooding the public form and the CRM with fake sign-ups
Honeypot field, origin check and server-side Turnstile verification of action and hostname, failing closed
Skipping the interface to talk straight to the database or API with the public key in hand.
Using the public Supabase key to read the database straight through PostgREST
RLS on every table, zero policies, grants revoked from anon and authenticated, functions executable only by service_role
Someone with some access trying to get more: becoming admin, reading what they shouldn't, keeping revoked access.
Logging into the panel with a valid Supabase account that isn't an admin
Allowlist re-checked on every request; an account outside it gets the same error as a wrong password
CSRF, fake webhooks, reused tokens, signed links and open redirects.
Forging counts on the capacity webhook to swap group invites
Constant-time secret comparison, 503 with no secret configured, and swaps only for the exact invite that filled up
Turning the short link into an open redirect for phishing
Target validated on save and on redirect, which only accepts the same origin; invites only in WhatsApp's official format
XSS, iframes, CSV formulas, disguised uploads and AI prompt manipulation.
Uploading HTML disguised as an image through the panel to serve it from Storage
Type checked by the first bytes, fresh UUID filename and per-type size limit
Blowing up the bill, exhausting quotas, flooding logs and knocking functions down with load.
A huge chunked body to exhaust the Function's CPU and memory
Stream read in chunks and cancelled past the limit, without trusting Content-Length
Enumerating who is in the base, scraping personal data, tying questions to people, extracting secrets.
Submitting known phone numbers to the sign-up to learn who is a supporter and which state they live in
Identical response for new and repeat numbers; the Function discards the RPC body and the SQL function only returns a boolean
An adversarial audit of the whole repository and of the production database (read-only) produced 9 findings: 2 high, 2 medium, 3 low and 2 informational. The fixes shipped in 5 batches on the same day, each with tests proving the behavior.
Privacy and anti-enumeration
- The sign-up endpoint was an oracle: the response said whether a WhatsApp number was already registered and in which state. For any known phone number, that revealed whether the person was a supporter and where they lived. The response is now identical for new and repeat numbers, the Function discards the RPC body unread, and the database function only returns a boolean.
- The short link always answers with the same body-less
302, whether the slug exists or not, so the route doesn't reveal which links exist. - No personal data in logs: for CRM errors, only the message is logged, never the echoed record; the success response isn't even read.
- Mandatory explicit consent, with the privacy policy version stored on each record.
Panel authentication and authorization
- Login protected by Cloudflare Turnstile verified server-side:
success,actionandhostnamemust all match, and any failure (missing token, secret or hostname allowlist, network error) denies access. - The Supabase session is kept in
HttpOnly; Secure; SameSite=Strictcookies scoped to/api/admin, invisible to page JavaScript. - On every request, the user is revalidated against Auth and checked against an admin allowlist. A valid account outside the list gets the same error as a wrong password.
- Every write checks the request origin; methods outside the explicit list get a
405.
Database
- RLS on every table, with no policies at all and grants revoked from
anonandauthenticated: the only way in is theservice_rolekey, which exists only inside the Functions. The lint stops secret names from appearing in files served to the browser. - No
SECURITY DEFINERfunctions, and all functions executable only byservice_role, trigger functions included (hygiene flagged by the audit). - The panel search escapes
%,_and\before they reachilike.
Input and abuse
- Real body-size limits: the stream is read in chunks and cancelled once it exceeds the cap, instead of trusting
Content-Length(which disappears with chunked transfer). Limits range from 4 KB to 60 KB depending on the route. - Public forms have a honeypot field, an origin check, and Turnstile with a per-form
action, switchable by environment variable so the code could ship before the widget was validated in production. - The group-capacity webhook compares its secret in constant time, fails closed (
503) when no secret is configured, and accepts at most 100 groups per call. - Panel uploads are type-checked by their first bytes (an HTML file renamed to
.pngis rejected), stored under a fresh UUID, and size-capped per type (15 MB images, 45 MB video).
Browser
- CSP on every page, with
frame-ancestors 'none',object-src 'none',base-uri 'none'andform-action 'self'; nounsafe-inlinein the panel. - HSTS,
X-Frame-Options: DENY,nosniff,Referrer-Policy, and aPermissions-Policythat disables camera, microphone, payment and USB (geolocation allowed only on-site, for the map). - A short link's target is editable text in the panel, so it's validated twice: on save and on redirect, which only accepts the same origin. Group invites are only accepted as
https://chat.whatsapp.com/<code>. Neither can become an open redirect.
07Technical challenges
Closing a sensitive-data oracle without breaking the flow
The sign-up endpoint returned duplicado and the existing record's state, and that fed the redirect to the group. The fix touched three layers at once: the Function now always returns { success: true }, the client uses the state from its own form, and the SQL function only returns {gravado}. Because the code had to work both before and after the SQL was reapplied in production, the Function drops the RPC body unread, and a test compares the responses for new and repeat numbers byte for byte.
Invite rotation without a race condition
Two readings of the same full group arriving together (or the panel swapping at the same moment) could burn two reserve invites. The swap UPDATE filters by state and by the invite that filled up, so only the first call finds the row; the second gets zero rows back and reports "invite already swapped". Counts identified only by state record the status but never trigger a swap, since a late reading from the old group would knock out the reserve that just went live. History, queue and count are handled by a single trigger, so all three swap paths behave the same.
A URL that passes the ad validator and still reaches the group
The ad platform's validator reads the landing page's HTML and rejects the campaign if it finds a WhatsApp group link. The ads route has no href, no meta refresh and no preconnect to that domain: the invite code travels in a data attribute, and the URL is assembled in the browser from pieces that don't form the domain on their own. The lint blocks anyone from putting the link back into that channel's HTML, because the failure would be silent: the page would keep working and only the ad campaign would go down.
Printed links that can never fail
A QR code on paper can't be patched. The short link, the group pages and the national network entry point turn any problem (unknown slug, state without a group, database down with a 3 s timeout) into a silent redirect to the national group or the home page, never a 404 or a 500. Redirects are sent with no-store so no intermediary caches an old target, and link-preview bots are excluded from click counts, otherwise one message forwarded to a group would turn into dozens of "clicks".
08Results
- In production throughout the campaign, August to October 2026, with 158 commits over 8 weeks.
- A security audit with 9 findings; 8 fixed in code on the same day, in 5 tested batches. The rest depends on manual configuration in the providers' dashboards.
- 209 automated tests passing and 178 structural lint checks, with zero runtime dependencies.
- Zero secrets in the tree or in git history (scanned for key and JWT patterns during the audit).
- 158
- commits
- 8 weeks
- timeframe
- 0
- runtime dependencies
- 209
- tests
- 178
- lint checks
- 9
- audit findings
- 12
- Pages Functions
- 25
- /api/admin actions
- 10
- tables with RLS
- 20
- SQL functions
- ~31.9k
- lines of code
how we measured
git rev-list --count HEAD
how we measured
git log: first commit 2026-08-13, last 2026-10-07
how we measured
package.json has no dependencies field
how we measured
node --test on the 19 tracked files in scripts/test (209 pass, 0 fail)
how we measured
count of 'throw new Error' in scripts/check.mjs
how we measured
SECURITY_AUDIT.md: 2 high, 2 medium, 3 low, 2 info
how we measured
files in functions/ (7 APIs, 3 generated pages, short link, middleware)
how we measured
router in functions/api/admin.js: 12 reads, 11 writes, login and logout
how we measured
create table + enable row level security in supabase/*.sql; 0 create policy
how we measured
create or replace function in supabase/*.sql; 0 security definer
how we measured
wc -l on tracked .js/.mjs/.css/.html/.sql/.py/.md files (cloc unavailable)
09Timeline
- Aug 2026
Landing page with sign-up through a Pages Function and Supabase; admin panel behind Turnstile; CRM sync.
- Sep 2026
Security audit: 9 findings fixed in 5 batches on the same day, with a test harness.
- Sep 2026
Trackable short links with QR codes, UTM attribution and per-link metrics in the panel.
- Sep 2026
Per-state group links, an ads variant with no invite in the HTML, and the capacity webhook.
- Sep 2026
Street action map built on the IBGE mesh with server-side geocoding.
- Sep 2026
Invite queue, history and automatic group swap at the cap, via a Postgres trigger.
- Oct 2026
Artwork gallery with signature-validated uploads; national group network with a cap editable in the panel.
10Stack
- HTML
- CSS
- JavaScript (sem framework)
- Canvas 2D
- SVG
- Web Share API
- Cloudflare Pages Functions
- PostgREST
- Supabase Auth
- PostgreSQL
- Row Level Security
- PL/pgSQL (gatilhos)
- Supabase Storage
- Cloudflare Pages
- _headers / _routes.json
- Node.js (build, lint, testes)
- Python + fontTools
- Cloudflare Turnstile
- CSP + HSTS
- Cookies HttpOnly / SameSite=Strict
- Allowlist de administradores
- Comparação de segredo em tempo constante
- Validação de arquivo por assinatura
11Tech sheet
- type
- mobilization platform
- stack
- vanilla JS · Pages Functions
- db
- Postgres · RLS deny-all
- auth
- Supabase Auth + Turnstile
- deploy
- Cloudflare Pages
- modules
- sign-up · groups · UTM links · map · letters · dashboard
- tests
- 209 passing · 178 lint checks
- status
- completed
The platform that brought content creators into the campaign to end online betting in Brazil: nationwide sign-ups, an inflation-proof public counter and a brute-force-hardened admin panel.
A public reporting channel with a triage panel where authorization lives in the database: role-based RLS, contacts only through an audited function, instant session revocation and a bot that saves evidence before it expires.
A WhatsApp relationship operation with human sending, immutable history and the database as the final word.
Want a system like this for your operation?
Node designs, builds and protects tailor-made platforms for campaigns, elected officials and movements.

TECHNOLOGY AND POLITICAL INTELLIGENCE
© 2026 NODE. All rights reserved.