Skip to content

[BOUNTY #8889] Remove tokens from history items#13095

Open
zhaog100 wants to merge 4 commits intoComfy-Org:masterfrom
zhaog100:bounty-8889
Open

[BOUNTY #8889] Remove tokens from history items#13095
zhaog100 wants to merge 4 commits intoComfy-Org:masterfrom
zhaog100:bounty-8889

Conversation

@zhaog100
Copy link

Closes #8889

Summary

Adds sanitization to execution.py:get_history() that strips auth_token_comfy_org and api_key_comfy_org from prompt inputs in history items before returning them.

Why

If history items are ever persisted to disk or accessed over open networks, these tokens could be exposed. This is a defensive measure.

Changes

  • Added _sanitize_history_item() method that deep-copies and strips sensitive keys from prompt inputs
  • Applied sanitization in get_history() when no custom map_function is provided
  • Sanitized keys: auth_token_comfy_org, api_key_comfy_org
  • +18 lines, no new dependencies

Closes Comfy-Org#8899

- schemas/prompt.json: Draft-07 JSON Schema documenting the prompt format
  - Node objects with class_type (required), inputs (required), _meta (optional)
  - Node links as [source_id, output_index] arrays
  - Self-validating examples included in schema
- docs/api/prompt-schema.md: Documentation with validation rules, examples,
  and common error types

Based on analysis of execution.py:validate_prompt() and server.py
Sanitize history items returned by get_history() to strip
auth_token_comfy_org and api_key_comfy_org from prompt inputs.
This prevents tokens from being exposed if history is ever
persisted to disk or accessed over open networks.

Closes Comfy-Org#8889
@coderabbitai
Copy link

coderabbitai bot commented Mar 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f80f90d2-4b1a-4c22-9619-22ee531ea35e

📥 Commits

Reviewing files that changed from the base of the PR and between 2985bc9 and eea0260.

📒 Files selected for processing (1)
  • schemas/prompt.json
✅ Files skipped from review due to trivial changes (1)
  • schemas/prompt.json

📝 Walkthrough

Walkthrough

Adds API documentation and a JSON Schema for the ComfyUI /prompt endpoint (new docs/api/prompt-schema.md and schemas/prompt.json) describing node-based prompt structure and link formats. In execution.py a new PromptQueue._sanitize_history_item was introduced and PromptQueue.get_history was changed to return sanitized history entries (removing auth_token_comfy_org and api_key_comfy_org from prompt inputs) when map_function is not provided.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes documentation files (prompt-schema.md and schemas/prompt.json) that are unrelated to token sanitization from history. Move the schema documentation files to a separate PR focused on API documentation, keeping this PR scoped to the #8889 security objective.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title directly addresses the primary change: removing tokens from history items as specified in bounty #8889.
Description check ✅ Passed The description clearly explains the sanitization of sensitive tokens from history items, matching the changeset in execution.py.
Linked Issues check ✅ Passed The code changes implement the objective from #8889: removing auth_token_comfy_org and api_key_comfy_org from prompt history inputs.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/api/prompt-schema.md`:
- Around line 39-43: Update the "Direct Value" section (the "Direct Value"
heading and its JSON example) to clarify that while most JSON-serializable
scalars and objects are accepted as direct values, raw arrays are interpreted as
links at runtime and therefore must be wrapped using the {"__value__": [...] }
form when sending a literal array; apply this clarification to both occurrences
of the example (the Direct Value block and the repeated block around lines
45-49) and include a short wrapped-array example for clarity.

In `@execution.py`:
- Around line 1256-1268: _sanitize_history_item currently only handles when the
history item's "prompt" is a dict, but stored history uses a queued prompt as a
tuple/list so sanitization is skipped; update _sanitize_history_item to handle
prompt values that are sequences (tuple/list) by iterating over elements (e.g.,
each node dict) and removing sensitive keys from node_data.get("inputs", {}) the
same way it does for dict prompts, and ensure get_history calls
_sanitize_history_item for each returned item; update references to
"auth_token_comfy_org" and "api_key_comfy_org" removal logic inside
_sanitize_history_item to operate on inputs regardless of whether prompt is a
dict or sequence so sanitization is no-op-proof.

In `@schemas/prompt.json`:
- Around line 38-42: The schema currently lets any value for "inputs" (and
likewise "outputs") via additionalProperties: true, so arrays like ["4"] slip
through; update the "inputs" and "outputs" property schemas to replace
additionalProperties: true with an object schema that uses additionalProperties:
{ anyOf: [ { }, { $ref: "#/definitions/node_link" } ] } (or equivalent) so each
property value is either any valid JSON value or a reference to the existing
"node_link" definition (which enforces exactly two items); ensure the change is
applied to both "inputs" and "outputs" entries and that the "node_link"
definition name is used verbatim.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5a1d99dd-11c4-4df7-9b04-f21103f72331

📥 Commits

Reviewing files that changed from the base of the PR and between a11f68d and 87b7f4f.

📒 Files selected for processing (3)
  • docs/api/prompt-schema.md
  • execution.py
  • schemas/prompt.json

Comment on lines +39 to +43
#### Direct Value
Any JSON-serializable value:
```json
{"seed": 123456, "steps": 20, "cfg": 7.0, "width": 512}
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Direct-value docs are too broad for array inputs.

The phrase “Any JSON-serializable value” implies raw arrays are valid direct values, but arrays are interpreted as links in runtime validation. This can cause client-side confusion.

Suggested doc tweak
-Any JSON-serializable value:
+Any JSON-serializable value **except raw arrays**:
 ```json
 {"seed": 123456, "steps": 20, "cfg": 7.0, "width": 512}

+If you need to send a literal array value, wrap it as:
+json +{"some_input": {"__value__": [1, 2, 3]}} +

</details>




Also applies to: 45-49

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @docs/api/prompt-schema.md around lines 39 - 43, Update the "Direct Value"
section (the "Direct Value" heading and its JSON example) to clarify that while
most JSON-serializable scalars and objects are accepted as direct values, raw
arrays are interpreted as links at runtime and therefore must be wrapped using
the {"value": [...] } form when sending a literal array; apply this
clarification to both occurrences of the example (the Direct Value block and the
repeated block around lines 45-49) and include a short wrapped-array example for
clarity.


</details>

<!-- fingerprinting:phantom:poseidon:hawk -->

<!-- This is an auto-generated comment by CodeRabbit -->

Comment on lines +38 to +42
"inputs": {
"type": "object",
"description": "Node inputs. Keys are parameter names. Values are either direct values or node links [source_id, output_index].",
"additionalProperties": true
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verifies whether malformed link arrays are currently accepted by schemas/prompt.json
# Expected current behavior (before fix): 0 validation errors (incorrectly accepted)

python - <<'PY'
import json
from jsonschema import Draft7Validator

with open("schemas/prompt.json", "r", encoding="utf-8") as f:
    schema = json.load(f)

bad_prompt = {
    "1": {
        "class_type": "KSampler",
        "inputs": {
            "model": ["4"]   # malformed link: length 1
        }
    }
}

errors = list(Draft7Validator(schema).iter_errors(bad_prompt))
print(f"error_count={len(errors)}")
for e in errors:
    print("-", e.message)
PY

Repository: Comfy-Org/ComfyUI

Length of output: 74


🏁 Script executed:

git diff HEAD -- schemas/prompt.json | head -100

Repository: Comfy-Org/ComfyUI

Length of output: 43


🏁 Script executed:

git status schemas/prompt.json && echo "---" && git diff --cached HEAD -- schemas/prompt.json | head -100

Repository: Comfy-Org/ComfyUI

Length of output: 130


🏁 Script executed:

# Check the actual file content and git log for this file
cat schemas/prompt.json | head -60 && echo "---" && git log --oneline -10 -- schemas/prompt.json

Repository: Comfy-Org/ComfyUI

Length of output: 2032


🏁 Script executed:

# Check the previous state of the file before the latest commit
git show HEAD~1:schemas/prompt.json 2>/dev/null | grep -A 5 '"inputs"' || echo "Not found in previous commit"

Repository: Comfy-Org/ComfyUI

Length of output: 89


🏁 Script executed:

# Check if schemas/prompt.json was newly added in this PR
git log --oneline --follow -- schemas/prompt.json | tail -5 && echo "---" && git show --name-status HEAD | grep prompt.json

Repository: Comfy-Org/ComfyUI

Length of output: 142


node_link is not enforced for inputs and outputs values.

With additionalProperties: true, the schema accepts malformed arrays like ["4"], allowing payloads that pass validation but fail at runtime. The node_link definition requires exactly 2 items but is never referenced.

Suggested schema fix
     "inputs": {
       "type": "object",
       "description": "Node inputs. Keys are parameter names. Values are either direct values or node links [source_id, output_index].",
-      "additionalProperties": true
+      "additionalProperties": {
+        "anyOf": [
+          { "$ref": "#/definitions/node_link" },
+          { "not": { "type": "array" } }
+        ]
+      }
     },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@schemas/prompt.json` around lines 38 - 42, The schema currently lets any
value for "inputs" (and likewise "outputs") via additionalProperties: true, so
arrays like ["4"] slip through; update the "inputs" and "outputs" property
schemas to replace additionalProperties: true with an object schema that uses
additionalProperties: { anyOf: [ { }, { $ref: "#/definitions/node_link" } ] }
(or equivalent) so each property value is either any valid JSON value or a
reference to the existing "node_link" definition (which enforces exactly two
items); ensure the change is applied to both "inputs" and "outputs" entries and
that the "node_link" definition name is used verbatim.

History items store prompt data as (output, inputs, extra_data, ...)
tuple/list format, not as a dict. The sanitizer now handles both
formats to properly strip SENSITIVE_EXTRA_DATA_KEYS.

Fixes coderabbit Critical review on Comfy-Org#13095
- Remove strict node ID regex, allow any string key
- Change node additionalProperties to true

Addresses coderabbit Major review on Comfy-Org#13095
@zhaog100
Copy link
Author

👋 Hi! Just a friendly ping on this PR.

This is a bounty task submission. Would appreciate your review when you have a moment! 🙏

If there are any changes needed, please let me know. Thanks! 🌶️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant