Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions moonraker/components/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import base64
import uuid
import hashlib
import hmac
import secrets
import os
import time
Expand Down Expand Up @@ -703,7 +704,7 @@ def validate_jwt(self, token: str) -> UserInfo:
def validate_api_key(self, api_key: str) -> UserInfo:
if not self.enable_api_key:
raise self.server.error("API Key authentication is disabled", 401)
if api_key and api_key == self.api_key:
if api_key and self.api_key and hmac.compare_digest(api_key, self.api_key):
return self.users[API_USER]
raise self.server.error("Invalid API Key", 401)

Expand Down Expand Up @@ -875,7 +876,7 @@ async def authenticate_request(
# Check API Key Header
if self.enable_api_key:
key: Optional[str] = request.headers.get("X-Api-Key")
if key and key == self.api_key:
if key and self.api_key and hmac.compare_digest(key, self.api_key):
return self.users[API_USER]

# If the force_logins option is enabled and at least one user is created
Expand Down