Add check fingerprint

This commit is contained in:
hlohaus
2025-08-09 09:52:26 +02:00
parent adb756ef45
commit 17d36d5106
3 changed files with 8 additions and 10 deletions

View File

@@ -22,7 +22,7 @@ class EasyChat(OpenaiTemplate, AuthFileMixin):
active_by_default = True
use_model_names = True
default_model = "gpt-oss-120b-free"
default_model = DEFAULT_MODEL.split("/")[-1]
model_aliases = {
DEFAULT_MODEL: default_model,
}

View File

@@ -261,10 +261,6 @@ class Api:
if path.startswith("/v1") or path.startswith("/api/") or (AppConfig.demo and path == '/backend-api/v2/upload_cookies'):
if request.method != "OPTIONS":
if user_g4f_api_key is None:
ip = request.headers.get("X-Forwarded-For", "")[:4].strip(":.")
country = request.headers.get("Cf-Ipcountry", "")
agent = request.headers.get("User-Agent", "")
debug.log(f"User: '{user}' G4F API key is required. IP: {ip}, Country: {country}, User-Agent: {agent}")
return ErrorResponse.from_message("G4F API key required", HTTP_401_UNAUTHORIZED)
if AppConfig.g4f_api_key is None and user is None:
return ErrorResponse.from_message("Invalid G4F API key", HTTP_403_FORBIDDEN)

View File

@@ -110,10 +110,12 @@ class Backend_Api(Api):
def get_public_key():
if not has_crypto:
return jsonify({"error": {"message": "Crypto support is not available"}}), 501
# if time.time() - int(base64.b64decode(request.cookies.get("fingerprint", "MA==")).decode()) > 60:
# If the fingerprint is older than 60 seconds, generate a new one
# resp = jsonify({"error": {"message": "Please refresh the page"}})
return resp
try:
diff = time.time() - int(base64.b64decode(request.cookies.get("fingerprint")).decode())
except Exception as e:
return jsonify({"error": {"message": "Invalid fingerprint"}}), 403
if diff > 60 * 60 * 2:
return jsonify({"error": {"message": "Please refresh the page"}}), 403
# Send the public key to the client for encryption
return jsonify({
"public_key": public_key_pem.decode(),
@@ -298,7 +300,7 @@ class Backend_Api(Api):
@app.route('/backend-api/v2/version', methods=['GET'])
def version():
resp = jsonify(self.get_version())
resp.set_cookie('fingerprint', base64.b64encode(str(int(time.time())).encode()).decode(), max_age=60, httponly=True, secure=True)
resp.set_cookie('fingerprint', base64.b64encode(str(int(time.time())).encode()).decode(), max_age=60 * 60 *2, httponly=True, secure=True)
return resp
@app.route('/backend-api/v2/create', methods=['GET'])