All case studies
~/cases/[classified]/prumo
confidential · NDAPlatforms & CRMsPresidential campaignAug 2026 → Oct 2026Completed

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.

0
runtime dependencies
209
tests
9
audit findings
10
tables with RLS
  • cloudflare
  • supabase
  • postgres
  • rls
  • anti-bot
  • csp
  • security-audit
  • lgpd
  • vanilla-js
  • webhooks
architecture.en.svgenlarge ↓

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 via meta refresh so 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.xml generated at build time with lastmod taken from git, JSON-LD kept consistent across pages, and a robots.txt with 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

real architecture · hover over the nodes
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

Backend and data
  • 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/admin handles 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 EXECUTE revoked from public, anon and authenticated and granted only to service_role; none is SECURITY DEFINER.
  • Invite rotation lives in the database. Swapping a state's active invite is a single UPDATE on whatsapp_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.
Frontend
  • No framework, no dependencies: package.json has no dependencies. The build copies files into dist/ 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-motion honored, and every image with alt, width and height.
  • Safe rendering in the panel: server data goes in through textContent/createElement, never innerHTML. 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.
Infrastructure and deploy
  • Cloudflare Pages building with npm run build into dist/. Secrets live in the project's encrypted variables, never in the repository (only an .env.example with placeholders).
  • _routes.json keeps static assets off the Functions path: images, CSS and JS don't wake the Worker, which cuts billed invocations.
  • _headers sets 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 _headers and the Worker-rendered page, diverging Disallow lists across robots.txt groups, 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:test with a mocked fetch, no dependencies, no network.

06Security

8 attacks considered, 8 defenses in production.

attackdefense
Bots and fake sign-ups

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

API shortcut

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

Privilege escalation

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

Forged origin and requests

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

Injection and hostile content

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

Cost and availability abuse

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

Data leakage and tracking

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, action and hostname must all match, and any failure (missing token, secret or hostname allowlist, network error) denies access.
  • The Supabase session is kept in HttpOnly; Secure; SameSite=Strict cookies 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 anon and authenticated: the only way in is the service_role key, which exists only inside the Functions. The lint stops secret names from appearing in files served to the browser.
  • No SECURITY DEFINER functions, and all functions executable only by service_role, trigger functions included (hygiene flagged by the audit).
  • The panel search escapes %, _ and \ before they reach ilike.

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 .png is 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' and form-action 'self'; no unsafe-inline in the panel.
  • HSTS, X-Frame-Options: DENY, nosniff, Referrer-Policy, and a Permissions-Policy that 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
how we measured

git rev-list --count HEAD

8 weeks
timeframe
how we measured

git log: first commit 2026-08-13, last 2026-10-07

0
runtime dependencies
how we measured

package.json has no dependencies field

209
tests
how we measured

node --test on the 19 tracked files in scripts/test (209 pass, 0 fail)

178
lint checks
how we measured

count of 'throw new Error' in scripts/check.mjs

9
audit findings
how we measured

SECURITY_AUDIT.md: 2 high, 2 medium, 3 low, 2 info

12
Pages Functions
how we measured

files in functions/ (7 APIs, 3 generated pages, short link, middleware)

25
/api/admin actions
how we measured

router in functions/api/admin.js: 12 reads, 11 writes, login and logout

10
tables with RLS
how we measured

create table + enable row level security in supabase/*.sql; 0 create policy

20
SQL functions
how we measured

create or replace function in supabase/*.sql; 0 security definer

~31.9k
lines of code
how we measured

wc -l on tracked .js/.mjs/.css/.html/.sql/.py/.md files (cloc unavailable)

09Timeline

  1. Aug 2026

    Landing page with sign-up through a Pages Function and Supabase; admin panel behind Turnstile; CRM sync.

  2. Sep 2026

    Security audit: 9 findings fixed in 5 batches on the same day, with a test harness.

  3. Sep 2026

    Trackable short links with QR codes, UTM attribution and per-link metrics in the panel.

  4. Sep 2026

    Per-state group links, an ads variant with no invite in the HTML, and the capacity webhook.

  5. Sep 2026

    Street action map built on the IBGE mesh with server-side geocoding.

  6. Sep 2026

    Invite queue, history and automatic group swap at the cap, via a Postgres trigger.

  7. Oct 2026

    Artwork gallery with signature-validated uploads; national group network with a cap editable in the panel.

10Stack

Frontend
  • HTML
  • CSS
  • JavaScript (sem framework)
  • Canvas 2D
  • SVG
  • Web Share API
Backend
  • Cloudflare Pages Functions
  • PostgREST
  • Supabase Auth
Data
  • PostgreSQL
  • Row Level Security
  • PL/pgSQL (gatilhos)
  • Supabase Storage
Infra
  • Cloudflare Pages
  • _headers / _routes.json
  • Node.js (build, lint, testes)
  • Python + fontTools
Security
  • 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

node@prumo: ~/cases/prumo
node@prumo ─────────────
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
$ npm test
ℹ tests 209
ℹ pass 209
ℹ fail 0
$ npm run lint
Lint estrutural concluído sem erros.
$ curl -s -X POST $SITE/api/cadastros -H 'content-type: application/json' -d @numero-ja-cadastrado.json
{"success":true}
# idêntico ao de um número novo: o endpoint não revela quem já está na base
$ curl -s -X POST $SITE/api/lotacao -d '{"uf":"SP","participantes":301}'
{"error":"Não autorizado."}
# segredo ausente ou errado: 401, comparação em tempo constante
$ curl -sI $SITE/l/slug-que-nao-existe
HTTP/2 302
location: $SITE/
cache-control: no-store
referrer-policy: no-referrer

© 2026 NODE. All rights reserved.