From 38e3ec87364c6b4812dabc403f071af1a3022648 Mon Sep 17 00:00:00 2001 From: eugenchio Date: Wed, 15 Jan 2025 16:31:38 +0200 Subject: [PATCH] Update contact form and newsletter handlers to check http method. --- lambda-functions/contact_form.py | 12 ++++++++++++ lambda-functions/newsletter_sign_up.py | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lambda-functions/contact_form.py b/lambda-functions/contact_form.py index e106531..8c7e84e 100644 --- a/lambda-functions/contact_form.py +++ b/lambda-functions/contact_form.py @@ -107,6 +107,18 @@ def send_email(event_body): def handle_contact_form(event, context): + if event['requestContext']['http']['method'] != 'POST': + return { + 'statusCode': 400, + 'headers': { + 'Content-Type': 'application/json' + }, + 'body': json.dumps({ + 'success': False, + 'message': 'Unsupported http method' + }) + } + if event['body']: try: body = json.loads(event['body']) diff --git a/lambda-functions/newsletter_sign_up.py b/lambda-functions/newsletter_sign_up.py index 1e73a5e..44f1ea7 100755 --- a/lambda-functions/newsletter_sign_up.py +++ b/lambda-functions/newsletter_sign_up.py @@ -75,6 +75,18 @@ def add_crisp_contact(email): def handle_newsletter_sign_up(event, context): + if event['requestContext']['http']['method'] != 'POST': + return { + 'statusCode': 400, + 'headers': { + 'Content-Type': 'application/json' + }, + 'body': json.dumps({ + 'success': False, + 'message': 'Unsupported http method' + }) + } + if event['body']: try: body = json.loads(event['body'])