Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
check key format
  • Loading branch information
LucifersCircle committed Dec 7, 2024
1 parent fe3c5e1 commit b293655
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import sqlite3
from flask import Flask, request, jsonify, render_template_string
from cryptography.fernet import Fernet
Expand Down Expand Up @@ -111,6 +112,11 @@ def add_key():
key = request.form.get('key')
if not key:
return jsonify({'error': 'Key is required'}), 400

# Validate the key using a regular expression
if not re.fullmatch(r'^[a-fA-F0-9]{64}$', key):
return jsonify({'error': 'Invalid key format. Only 64-character alphanumeric keys are allowed.'}), 400

try:
print(f"Received key: {key}")
encrypted_key = cipher.encrypt(key.encode())
Expand Down

0 comments on commit b293655

Please sign in to comment.