Repository navigation
Add Comfy-Usage-Source header to all CLI API requests #932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a1d89df
dd60302
cafbb28
25b00b4
7d27a63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ | |
| from comfy_cli.comfy_client import Client, Unauthenticated, extract_output_entries | ||
| from comfy_cli.credentials import DataPlaneToken | ||
| from comfy_cli.host_port import report_usage_error, validate_host | ||
| from comfy_cli.http import NoRedirectHandler, build_http_only_opener | ||
| from comfy_cli.http import USAGE_SOURCE_HEADERS, NoRedirectHandler, build_http_only_opener | ||
| from comfy_cli.http import target_auth_headers as _auth_headers | ||
| from comfy_cli.output import get_renderer | ||
| from comfy_cli.output import rprint as pprint | ||
|
|
@@ -393,7 +393,7 @@ def _upload_file(path: Path, target: Any, *, overwrite: bool) -> dict: | |
| url = target.url("upload/image") | ||
| req = urllib.request.Request(url, data=body, method="POST") | ||
| req.add_header("Content-Type", f"multipart/form-data; boundary={boundary}") | ||
| for hdr, val in _auth_headers(target).items(): | ||
| for hdr, val in {**USAGE_SOURCE_HEADERS, **_auth_headers(target)}.items(): | ||
| req.add_header(hdr, val) | ||
|
|
||
| with _TRANSFER_OPENER.open(req, timeout=_UPLOAD_TIMEOUT_S) as resp: | ||
|
|
@@ -946,7 +946,7 @@ def execute_download( | |
| dest = Path(out_dir or _default_out_dir()) | ||
| dest.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| auth_hdrs = _auth_headers(target) | ||
| auth_hdrs = {**USAGE_SOURCE_HEADERS, **_auth_headers(target)} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: rg -n -C 15 "_AUTH_HEADERS_TO_STRIP|_DownloadRedirectHandler|USAGE_SOURCE_HEADERS|auth_hdrs = " comfy_cli/command/transfer.pyRepository: Comfy-Org/comfy-cli Length of output: 6761 🏁 Script executed: rg -n -C 12 "auth_hdrs|USAGE_SOURCE_HEADERS" comfy_cli/command/transfer.py comfy_cli/http.pyRepository: Comfy-Org/comfy-cli Length of output: 19070 Strip
Suggested fix-_AUTH_HEADERS_TO_STRIP = frozenset({"authorization", "x-api-key", "x-comfy-api-key", "cookie"})
+_AUTH_HEADERS_TO_STRIP = frozenset(
+ {"authorization", "x-api-key", "x-comfy-api-key", "cookie", "comfy-usage-source"}
+)🤖 Prompt for AI Agents |
||
| saved_files: list[dict[str, Any]] = [] | ||
| saved_paths: list[str] = [] | ||
| short_id = prompt_id[:8] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Prevent attribution-header forwarding across third-party redirects. Both request paths add
Comfy-Usage-Sourceand use clients that follow redirects. A cross-host redirect can therefore send the header to a host outside the scope documented incomfy_cli/http.py.comfy_cli/command/generate/app.py#L1073-L1073: restrict the header to Comfy-owned destinations, including redirected destinations, or disable redirects.comfy_cli/command/jobs.py#L160-L160: remove the header before a cross-host redirect, or refuse that redirect.📍 Affects 2 files
comfy_cli/command/generate/app.py#L1073-L1073(this comment)comfy_cli/command/jobs.py#L160-L160🤖 Prompt for AI Agents