Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions api/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ROUTES = {
partner: "hello@openral.com",
};

const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const EMAIL_RE = /^[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@(?:(?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,63}$/;

// Best-effort, per-instance rate limit. Vercel functions are ephemeral and
// horizontally scaled, so this is not a hard global cap — it just blunts a
Expand All @@ -34,7 +34,7 @@ function rateLimited(ip) {
recent.push(now);
hits.set(ip, recent);
if (hits.size > 5000) hits.clear(); // bound memory on a long-lived instance
return recent.length > RATE_LIMIT.max;
return recent.length >= RATE_LIMIT.max;
}

function clamp(s, n) {
Expand Down Expand Up @@ -75,9 +75,9 @@ export default async function handler(req, res) {
const name = clamp(body.name, 120);
const email = clamp(body.email, 200);
const message = clamp(body.message, 5000);
const honeypot = clamp(body.company, 100); // optional anti-spam trap
const companyField = clamp(body.company, 100); // honeypot (anti-spam trap) field

if (honeypot) return res.status(200).json({ ok: true }); // silently drop bots
if (companyField) return res.status(200).json({ ok: true }); // silently drop bots
if (!name || !email || !message) {
return res.status(400).json({ error: "Name, email and message are required." });
}
Expand Down