Skip to content

Commit

Permalink
Added honeypot field handling
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminEHowe committed Jul 13, 2024
1 parent f591d31 commit bfb7895
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions functions/api/contact.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export async function onRequest(context) {
const HONEYPOT_FIELD = "name";

if (context.request.method !== "POST") {
return new Response("Invalid request method", { status: 405 });
}
Expand All @@ -7,6 +9,12 @@ export async function onRequest(context) {
const fields = Object.fromEntries(formData.entries());
fields.cf = context.request.cf;
fields.headers = Object.fromEntries(context.request.headers.entries());
if (fields[HONEYPOT_FIELD] !== "") {
return Response.redirect(context.request.headers.get("Referer"), 303);
} else {
delete fields[HONEYPOT_FIELD];
}

const url = new URL(context.request.url);

const sent = await sendFormViaResend({
Expand Down

0 comments on commit bfb7895

Please sign in to comment.