mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-10-19 22:54:43 +08:00
Add check fingerprint
This commit is contained in:
@@ -22,7 +22,7 @@ class EasyChat(OpenaiTemplate, AuthFileMixin):
|
|||||||
active_by_default = True
|
active_by_default = True
|
||||||
use_model_names = True
|
use_model_names = True
|
||||||
|
|
||||||
default_model = "gpt-oss-120b-free"
|
default_model = DEFAULT_MODEL.split("/")[-1]
|
||||||
model_aliases = {
|
model_aliases = {
|
||||||
DEFAULT_MODEL: default_model,
|
DEFAULT_MODEL: default_model,
|
||||||
}
|
}
|
||||||
|
@@ -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 path.startswith("/v1") or path.startswith("/api/") or (AppConfig.demo and path == '/backend-api/v2/upload_cookies'):
|
||||||
if request.method != "OPTIONS":
|
if request.method != "OPTIONS":
|
||||||
if user_g4f_api_key is None:
|
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)
|
return ErrorResponse.from_message("G4F API key required", HTTP_401_UNAUTHORIZED)
|
||||||
if AppConfig.g4f_api_key is None and user is None:
|
if AppConfig.g4f_api_key is None and user is None:
|
||||||
return ErrorResponse.from_message("Invalid G4F API key", HTTP_403_FORBIDDEN)
|
return ErrorResponse.from_message("Invalid G4F API key", HTTP_403_FORBIDDEN)
|
||||||
|
@@ -110,10 +110,12 @@ class Backend_Api(Api):
|
|||||||
def get_public_key():
|
def get_public_key():
|
||||||
if not has_crypto:
|
if not has_crypto:
|
||||||
return jsonify({"error": {"message": "Crypto support is not available"}}), 501
|
return jsonify({"error": {"message": "Crypto support is not available"}}), 501
|
||||||
# if time.time() - int(base64.b64decode(request.cookies.get("fingerprint", "MA==")).decode()) > 60:
|
try:
|
||||||
# If the fingerprint is older than 60 seconds, generate a new one
|
diff = time.time() - int(base64.b64decode(request.cookies.get("fingerprint")).decode())
|
||||||
# resp = jsonify({"error": {"message": "Please refresh the page"}})
|
except Exception as e:
|
||||||
return resp
|
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
|
# Send the public key to the client for encryption
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"public_key": public_key_pem.decode(),
|
"public_key": public_key_pem.decode(),
|
||||||
@@ -298,7 +300,7 @@ class Backend_Api(Api):
|
|||||||
@app.route('/backend-api/v2/version', methods=['GET'])
|
@app.route('/backend-api/v2/version', methods=['GET'])
|
||||||
def version():
|
def version():
|
||||||
resp = jsonify(self.get_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
|
return resp
|
||||||
|
|
||||||
@app.route('/backend-api/v2/create', methods=['GET'])
|
@app.route('/backend-api/v2/create', methods=['GET'])
|
||||||
|
Reference in New Issue
Block a user