All case studies
~/cases/[classified]/segundo-turno
confidential · NDAHardened landing pagesPresidential campaignOct 2026Completed

P-09

Segundo Turno

A static, build-free page with its sign-up hardened at the edge: four layers against bots before any data reaches the CRM.

client████Unofficial volunteer support network during a presidential runoff

Landing page for a volunteer mobilization network during a presidential runoff, reached almost always on a phone from WhatsApp links. It brings together a livestream, groups, a PDF guide, video scripts and a sign-up that goes through a honeypot, a timing check, Workers KV rate limiting and Cloudflare Turnstile before writing the contact to a self-hosted Mautic instance along with LGPD proof of consent. Live on the day of the first commit.

5 days
active period
0
npm dependencies
10/h per IP
rate limit
5
security headers
  • cloudflare
  • anti-bot
  • crm
  • rate-limiting
  • lgpd
  • vanilla-js
  • seo
  • ci
architecture.en.svgenlarge ↓

01Overview

Segundo Turno ("runoff" in Portuguese) is the front door of a volunteer network of communicators, activists and journalists that came together in the three weeks between the first round and the runoff of a presidential election. The page states plainly that it is unofficial: it is not a party or campaign channel.

Almost all traffic arrives through links shared on WhatsApp and social media, on a phone, often on a poor connection. On a single screen, a visitor can watch the recording of the kickoff meeting, pick a WhatsApp group that still has room, download the research guide as a PDF, grab a ready-to-shoot video script and, if they want to do more, leave their name, email, mobile number, state and city.

The site is static, with no build step, deployed on Cloudflare Pages. The only dynamic piece is an edge function that receives the sign-up, filters bots through four layers and writes the contact to a self-hosted Mautic instance, together with the proof of consent that Brazil's data protection law (LGPD) requires.

02The problem

  • Days, not weeks. The page had to be live the same day as the kickoff meeting, and the runoff was three weeks out. There was no time for a product, only for a page that worked on any phone.
  • A hostile audience by default. A political page with an open form attracts bots and bulk junk submissions, which pollute the list and burn email sender reputation.
  • Consent you can prove. A contact list used for outreach has to answer "when, from where, and with what wording did this person agree?". And it could not be mixed with any official campaign's database, since the page presents itself as independent.
  • Content that changes by the hour. WhatsApp groups fill up, the livestream becomes a recording, materials get replaced. Whoever edits the page cannot depend on a build pipeline.

03The solution

  • Livestream up top. A YouTube player embedded in the hero. A script switches the meeting state based on Brasília time: countdown, "live now", "meeting held". The static HTML already ships in the current state, which is what search engines and AI crawlers read without running JS.
  • Groups and materials as open lists (<details open>) inside the cards, with no extra route. Marking a group as full means editing one line of HTML.
  • /roteiros: 5 short video scripts with target audience, format and a "Copy script" button that assembles title and paragraphs ready to paste into a teleprompter (Clipboard API with an execCommand fallback).
  • "Want to help?" sign-up with dependent state and city dropdowns, populated from a local table of 5,571 municipalities across 27 states (official IBGE data). Phone mask, validation that focuses the first invalid field, and messages announced to screen readers.
  • Per-link source attribution. ?de=insta or utm_source becomes a de-insta tag on the contact, so the team can tell which channel drives sign-ups.
  • A real 404. Without a 404.html, Pages serves the home page with a 200 for any URL. The error page uses absolute paths because it is served at any depth (/a/b/c).
  • Discoverability. sitemap.xml, JSON-LD (WebSite, WebPage, an ItemList of scripts) whose dateModified is tied to a visible <time> in the footer, and instant search-engine notification via IndexNow.
  • Four anti-bot layers at the edge: honeypot and too-fast submissions get a fake 200, rate limiting returns 429 from the 11th request in an hour, and Turnstile is verified server-side.
  • LGPD proof of consent stored on the contact itself: UTC timestamp, IP, page, link source and the exact checkbox wording.
  • CRM credentials live only in edge secrets; without them the function fails closed with a 503 instead of accepting data.
  • Three domains collapsed into one canonical via 301, and the public preview set to noindex, in a 29-line middleware.
  • No build, no package.json: hand-written HTML, CSS and JS, deployed by GitHub Actions on every push.
  • 5,571 municipalities in dependent dropdowns, with no external API call.

04Architecture

real architecture · hover over the nodes
Read the diagram as a list (13 components, 14 connections)

Components

  • Channels: WhatsApp and social<br>links with ?de=origin, Bots and automated<br>submissions
  • Cloudflare Pages: _middleware.js<br>301 to canonical domain<br>security headers<br>noindex on preview, Static, no build<br>index · /roteiros · 404<br>styles.css · app.js · cidades.js, Pages Function<br>POST /api/cadastro, Workers KV<br>RATE_KV · 10 submissions/h/IP, Real-time Logs<br>[BLOQUEIO:motivo] · [CADASTRO:ok]

Connections

  • WhatsApp and social<br>links with ?de=origin → Visitor<br>(phone)
  • Visitor<br>(phone) → _middleware.js<br>301 to canonical domain<br>security headers<br>noindex on preview
  • Bots and automated<br>submissions → _middleware.js<br>301 to canonical domain<br>security headers<br>noindex on preview
  • _middleware.js<br>301 to canonical domain<br>security headers<br>noindex on preview → Static, no build<br>index · /roteiros · 404<br>styles.css · app.js · cidades.js
  • _middleware.js<br>301 to canonical domain<br>security headers<br>noindex on preview → Pages Function<br>POST /api/cadastro
  • Visitor<br>(phone) → Cloudflare Turnstile<br>invisible widget + siteverify (token)
  • Pages Function<br>POST /api/cadastro → Pages Function<br>POST /api/cadastro (honeypot · timing · validation)
  • Pages Function<br>POST /api/cadastro → Workers KV<br>RATE_KV · 10 submissions/h/IP
  • Pages Function<br>POST /api/cadastro → Cloudflare Turnstile<br>invisible widget + siteverify (siteverify)
  • Pages Function<br>POST /api/cadastro → Self-hosted Mautic<br>REST API · Basic Auth<br>contact · tags · consent note (upsert by email)
  • Pages Function<br>POST /api/cadastro → Real-time Logs<br>[BLOQUEIO:motivo] · [CADASTRO:ok]
  • Static, no build<br>index · /roteiros · 404<br>styles.css · app.js · cidades.js → YouTube<br>embedded live stream (iframe)
  • GitHub Actions<br>wrangler pages deploy → Edge
  • Static, no build<br>index · /roteiros · 404<br>styles.css · app.js · cidades.js → IndexNow<br>sitemap · JSON-LD

Diagram labels are in Portuguese, as in the codebase.

Every request first hits the middleware, which normalizes the host and sets the headers. Everything else is a static file served from the edge. The browser never talks to Mautic: only the function knows its URL and credentials.

05Under the hood

Backend and data

The backend is a single Pages Function, functions/api/cadastro.js (159 lines), that accepts only POST (any other method gets a 405). The order of checks is deliberate:

  1. Configuration. Without Mautic credentials it returns 503, and the form says it couldn't send, instead of accepting data that would never be stored.
  2. Honeypot and timing. A filled hidden website field, or a submission less than 2 s after the form mounted, gets 200 {ok:true} and is dropped. The bot sees success and gets no signal to adapt.
  3. Per-IP rate limit (CF-Connecting-IP) on Workers KV: 10 submissions per hour. Beyond that, 429.
  4. Turnstile. The invisible widget's token is checked against the siteverify API along with the client IP; an invalid token gets a 403.
  5. Server-side validation, independent of the browser's: max length per field (name 120, email 200, city 120, source 40), email regex, phone stripped to digits and required to have 10 or 11, a 2-letter state code, and consent required as the boolean true. The link source is restricted to [a-z0-9-].

Once the checks pass, the name is split into firstname/lastname, the phone becomes E.164 (+55…), and the contact is created or updated in Mautic via POST /api/contacts/new, which deduplicates on email, with overwriteWithBlank: false so a resubmission never wipes earlier data. Then, without being able to fail the response:

  • a note on the contact's timeline holding the proof of consent: UTC timestamp, IP, state and city, referring page, link source and the exact checkbox wording. Every resubmission adds a new note, since each one is a consent event;
  • optional addition to a segment (MAUTIC_SEGMENT_ID).

Default tags: segundo-turno (configurable), aceite-lgpd (LGPD consent) and de-<source>. A failure on the note or segment only goes to the log; the main record is already saved.

Frontend

Hand-written HTML, CSS and JavaScript, with no framework, no bundler and no package.json: 629 lines of HTML across 3 pages, 1,087 lines of CSS and 319 lines of browser JS (app.js and roteiros.js), plus the generated municipality table.

  • Mobile first. Stacked layout, a sticky bar that only appears once the player scrolls out of view (IntersectionObserver), and four cards that become a 2×2 grid on desktop so the group lists don't get squeezed.
  • Works without JS. Everything is readable and clickable with JavaScript off. Only the form submission and the copy button depend on it, and the button is hidden if JS doesn't load.
  • Accessibility. aria-live regions for the meeting state and the form status (screen readers hear the state change, never a ticking clock); Esc closes an open list and returns focus to its header; focus moves to the confirmation after submitting; prefers-reduced-motion is honored for scrolling and animation.
  • Weight under control. The brand fonts were converted into Latin-subset woff2 files (3 files, about 120 KB total) with preload; the headline only animates once its font arrives, with a 1.2 s fallback so it is never left hidden. The decorative brushstroke is a PNG inlined as a data URI in a CSS mask, because a mask loaded from an external file doesn't work under file://.
  • Cache busting without a build. CSS and JS use a hand-bumped ?v= shared across all three pages.
Infrastructure and deploy
  • Cloudflare Pages serves the repository root as the site (pages_build_output_dir = ".") and functions/ as the API, with no compile step.
  • Continuous deployment through GitHub Actions. The Pages project was created by direct upload, a type Cloudflare doesn't allow converting to native Git integration. The workaround is a workflow that runs wrangler pages deploy on every push to main, passing the commit hash and message, with concurrency so deploys never overlap and contents: read permissions.
  • Three domains, one canonical. The middleware 301-redirects any custom host to the canonical domain, preserving path and query. The *.pages.dev host stays up as a preview, with X-Robots-Tag: noindex so it doesn't compete in search.
  • Secrets live only in Pages. Mautic credentials and the Turnstile secret are encrypted project secrets; the repo only ships a .dev.vars.example with placeholder values.
  • Local testing with wrangler pages dev, a simulated KV namespace, and a git-ignored .dev.vars.

06Security

6 attacks considered, 6 defenses in production.

attackdefense
Bots and fake sign-ups

Scripts that flood forms, inflate numbers or sweep the site for openings.

  • A bot mass-submits the form with fake data

    An invisible honeypot and submissions under 2 s get a fake 200 and are dropped, giving the bot no signal to adapt

  • A script fires hundreds of submissions from one IP

    A per-IP counter in Workers KV: from the 11th request within the hour, 429

API shortcut

Skipping the interface to talk straight to the database or API with the public key in hand.

  • Skip the JavaScript and send an arbitrary payload straight to the API

    Validation is redone on the server: per-field length caps, email regex, digits-only phone, 2-letter state, boolean consent and a character allowlist on the source

Injection and hostile content

XSS, iframes, CSV formulas, disguised uploads and AI prompt manipulation.

  • Frame the page or abuse MIME sniffing

    The middleware sets X-Frame-Options SAMEORIGIN, nosniff, Referrer-Policy and Permissions-Policy on every response

Data leakage and tracking

Enumerating who is in the base, scraping personal data, tying questions to people, extracting secrets.

  • Pull the CRM credentials out of the browser

    The browser only talks to the edge function; Mautic's URL and credentials exist only as Pages secrets, and the function fails closed without them

Tampering and audit trail

Fiddling with counts, wiping the base, editing history or denying what was authorized.

  • Dispute that the person ever consented

    Each submission writes a note on the contact with UTC timestamp, IP, page, source and the exact checkbox wording, plus an aceite-lgpd tag

A political page with an open form is a target. The defenses sit at the edge, before any data reaches the CRM.

Four layers against automation

Layer What it does Response
website honeypot off-screen field, tabindex=-1, aria-hidden, autocomplete=off fake 200, dropped
Fill time form_elapsed_ms < 2,000 ms fake 200, dropped
Per-IP rate limit Workers KV counter, 10/h, 1 h TTL 429
Cloudflare Turnstile invisible widget; token verified via siteverify with remoteip 403

The first two layers lie on purpose: a bot that gets a success response has no reason to change tactics. Verified locally with wrangler pages dev: the honeypot and a too-fast submission both return {"ok":true} with a 200, and from the 11th request from the same IP within the window the function answers 429.

Validation and data hygiene. The browser validates for user experience; the server validates again, with a length cap on every field, normalization (lowercased email, digits-only phone, uppercased state) and a character allowlist on the link source, which becomes a CRM tag.

Secrets and attack surface. The browser never sees Mautic's URL or credentials. Authentication is HTTP Basic with a dedicated user limited to API and contact permissions. With no credentials configured, the function fails closed (503) rather than accepting data. Mautic errors become a generic 502, and the upstream body only reaches the log, truncated.

LGPD (Brazil's data protection law).

  • Explicit opt-in checkbox, enforced on the server (aceite === true, not merely truthy).
  • Proof of consent stored with the contact: UTC timestamp, IP, page, link source and the exact text the person checked. That text is duplicated as a constant in the function, with a code comment to change both together.
  • An aceite-lgpd tag to segment people who consented.
  • A separate, dedicated database: the page declares itself unofficial and, as a project rule, never writes to any official campaign database.

HTTP hardening. On every response, static files included: X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN, Referrer-Policy: strict-origin-when-cross-origin, a Permissions-Policy that disables camera, microphone and geolocation, and X-XSS-Protection. API responses carry Cache-Control: no-store.

Observability. Every block emits a [BLOQUEIO:bot|rate-limit|turnstile|validacao] line with IP and User-Agent; every accepted sign-up emits [CADASTRO:ok]. An ongoing attack is visible in Pages Real-time Logs with no extra tooling.

07Technical challenges

The invisible Turnstile freezing the form

The first integration rendered the widget from several places (script already loaded, a delayed DOMContentLoaded, load) and, on a submit without a token, polled every 200 ms for up to 10 s. On a slow phone, the Turnstile script arrived late and the button got stuck on "Verifying…". The fix replaced polling with events: the Turnstile script loads with render=explicit and an onload callback that renders the widget exactly once; a submission that arrives before the token is parked as a pending function and fired by Turnstile's own callback; the error-callback re-enables the button with a clear message; and after any failure the widget is reset to issue a fresh token.

One canonical domain, no duplicate content

Three domains point to the same project, and the *.pages.dev preview is public. Left alone, search engines would see four copies of the page. The middleware handles both in 29 lines: a 301 from any custom host to the canonical one, preserving path and query, and noindex on the preview, which stays useful for checking deployments.

A dynamic page that must read correctly without JS

The meeting state changes by the hour, but crawlers and AI systems read raw HTML. The answer was to invert it: the static HTML always ships in the current state and JS only updates it when needed. Alongside came JSON-LD that describes only what is visible, and a single last-updated date repeated in the footer <time>, the dateModified and the sitemap lastmod.

Geographic sign-up with no external API

State and city are dependent dropdowns, with no third-party call on every state change: all 5,571 municipalities live in one JS file served by the page itself, and the server receives values picked from a closed list instead of free text.

08Results

  • Live on the same day as the first commit (Oct 5, 2026), with the livestream, groups, materials and a CRM-integrated sign-up.
  • From first to last commit: 5 days and 30 commits by 2 authors, covering sign-up, security, SEO and a second page.
  • Sign-up protected by 4 anti-automation layers, all of them logged.
  • No JavaScript libraries, no package.json and no build step: the only third-party scripts are Turnstile and the YouTube player.
30
commits
how we measured

git log --oneline | wc -l

5 days
active period
how we measured

git log: first commit 2026-10-05, last 2026-10-09

2
authors
how we measured

git log --format=%an | sort -u

3
pages
how we measured

index.html, roteiros.html, 404.html

1
endpoints
how we measured

functions/api/cadastro.js (POST /api/cadastro) + functions/_middleware.js

10/h per IP
rate limit
how we measured

RATE_LIMIT and RATE_WINDOW in functions/api/cadastro.js; 429 on the 11th submission, checked with wrangler pages dev

5
security headers
how we measured

HEADERS_SEGURANCA in functions/_middleware.js

5,571
municipalities
how we measured

count of CIDADES_BR entries in cidades.js (27 states)

5
video scripts
how we measured

unique roteiro-N ids in roteiros.html

0
npm dependencies
how we measured

there is no package.json in the repository

1,087
CSS lines
how we measured

non-empty lines of styles.css

629
HTML lines
how we measured

non-empty lines of index.html, roteiros.html and 404.html

507
JS lines
how we measured

non-empty lines of app.js, roteiros.js and functions/, without the generated cidades.js table

09Timeline

  1. 05 Oct 2026

    Page live with livestream, groups and a sign-up sent to Mautic through a Pages Function

  2. 05 Oct 2026

    LGPD consent proof on the contact, per-link source tags and a canonical domain via 301

  3. 05 Oct 2026

    Continuous deployment through GitHub Actions, working around the direct-upload Pages project

  4. 06 Oct 2026

    Video scripts page and a real 404

  5. 06 Oct 2026

    SEO/GEO audit, sitemap, JSON-LD, noindex on the preview and IndexNow

  6. 09 Oct 2026

    State and city with 5,571 municipalities, Turnstile and KV rate limiting

10Stack

Frontend
  • HTML5
  • CSS3 sem framework
  • JavaScript sem dependências
  • IntersectionObserver
  • Clipboard API
  • woff2 em subset
Backend
  • Cloudflare Pages Functions
  • Middleware de borda
Data
  • Mautic auto-hospedado (API REST)
  • Workers KV
  • Tabela de municípios do IBGE
Infra
  • Cloudflare Pages
  • Wrangler 4
  • GitHub Actions
  • DNS Cloudflare (3 domínios)
Security
  • Cloudflare Turnstile
  • Rate limit por IP em KV
  • Honeypot
  • Checagem de tempo de preenchimento
  • Headers de segurança
  • Validação no servidor
  • Prova de consentimento LGPD

11Tech sheet

node@segundo-turno: ~/cases/segundo-turno
node@segundo-turno ─────────────
type
landing page + edge function
stack
html · css · vanilla js
runtime
cloudflare pages functions
crm
mautic (self-hosted)
antibot
honeypot · timing · kv rate limit · turnstile
deploy
github actions → wrangler
build
none
status
completed
$ npx wrangler pages dev .
Using secrets defined in .dev.vars
env.RATE_KV (local) KV Namespace
[wrangler:info] Ready on http://localhost:8788
$ curl -s localhost:8788/api/cadastro
{"ok":false,"erro":"use POST"} # 405
$ curl -s -X POST localhost:8788/api/cadastro -d '{"website":"http://spam","form_elapsed_ms":9000}'
{"ok":true} # 200 falso: honeypot preenchido, descartado
[BLOQUEIO:bot] motivo=honeypot/timing
$ curl -s -X POST localhost:8788/api/cadastro -d '{"email":"nao-e-email", ...}'
{"ok":false,"erro":"e-mail inválido"} # 400
$ for i in $(seq 12); do curl -s -o /dev/null -w '%{http_code} ' -X POST localhost:8788/api/cadastro -d '{}'; done
400 400 400 400 400 400 400 400 400 400 429 429
[BLOQUEIO:rate-limit] contagem=10
$ curl -sI localhost:8788/ | grep -iE 'x-|policy'
Permissions-Policy: camera=(), microphone=(), geolocation=()
X-Frame-Options: SAMEORIGIN
referrer-policy: strict-origin-when-cross-origin
x-content-type-options: nosniff

© 2026 NODE. All rights reserved.