Skip to content

Commit

Permalink
Make opt in to only restrict API calls for prompt and apis using REST…
Browse files Browse the repository at this point in the history
…RICT_APIS_ONLY. Only restricting queuing/prompting a job
  • Loading branch information
Layoric committed Nov 21, 2024
1 parent a9ffbc3 commit baa503e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions comfy/ai-agent-extension/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ async def engines_list(request):
async def simple_api_key_auth(request, handler):
# Allow paths that aren't /prompt or don't start with /api
path = request.path
restrict_apis_only = os.getenv('RESTRICT_APIS_ONLY', 'false').lower() == 'true'
if path != '/prompt' and not path.startswith('/api/prompt') and restrict_apis_only:
return await handler(request)

auth_token = os.getenv('AGENT_PASSWORD')
is_authorized = False
Expand All @@ -121,6 +118,11 @@ async def simple_api_key_auth(request, handler):
if request.query['apiKey'] == auth_token:
is_authorized = True


restrict_apis_only = os.getenv('RESTRICT_APIS_ONLY', 'false').lower() == 'true'
if path != '/prompt' and not path.startswith('/api/prompt') and restrict_apis_only and is_authorized is False:
is_authorized = True

# Return error if neither authentication method succeeded
if not is_authorized:
return web.json_response({
Expand Down

0 comments on commit baa503e

Please sign in to comment.