AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
refactor(platform): remove AgentInput secret toggle + simplify graph-export stripping (#13145)
Krzysztof Czerwinski205079f09573
diff --git a/autogpt_platform/backend/backend/blocks/io.py b/autogpt_platform/backend/backend/blocks/io.pyindex 2ef9999da4..67aa8b54e2 100644--- a/autogpt_platform/backend/backend/blocks/io.py+++ b/autogpt_platform/backend/backend/blocks/io.py@@ -54,11 +54,6 @@ class AgentInputBlock(Block):default=False,advanced=True,)- secret: bool = SchemaField(- description="Whether the input should be treated as a secret.",- default=False,- advanced=True,- )def generate_schema(self):return copy.deepcopy(self.get_field_schema("value"))@@ -144,11 +139,6 @@ class AgentOutputBlock(Block):default=False,advanced=True,)- secret: bool = SchemaField(- description="Whether the output should be treated as a secret.",- default=False,- advanced=True,- )def generate_schema(self):return self.get_field_schema("value")@@ -491,7 +481,7 @@ class AgentDropdownInputBlock(AgentInputBlock):"restricted to these values. Leave empty for free-text input."),validation_alias=AliasChoices("options", "placeholder_values"),- json_schema_extra={"advanced": False, "secret": False},+ json_schema_extra={"advanced": False},)def generate_schema(self):diff --git a/autogpt_platform/backend/backend/data/graph.py b/autogpt_platform/backend/backend/data/graph.pyindex 4ce30059c3..8f3175830f 100644--- a/autogpt_platform/backend/backend/data/graph.py+++ b/autogpt_platform/backend/backend/data/graph.py@@ -161,53 +161,32 @@ class NodeModel(Node):def stripped_for_export(self) -> "NodeModel":"""- Returns a copy of the node model, stripped of any non-transferable properties+ Returns a copy of the node model with non-transferable references removed:+ - fields the block schema declares as a `CredentialsMetaInput`+ (point at the original owner's credentials store; importers must+ wire up their own)+ - fields the block schema marks with `secret: true` via+ `SchemaField(secret=True)` (block-author-declared sensitive values)+ - `webhook_id` (points at the original owner's webhook subscription)"""stripped_node = self.model_copy(deep=True)- # Remove credentials and other (possible) secrets from node inputif stripped_node.input_default:- stripped_node.input_default = NodeModel._filter_secrets_from_node_input(- stripped_node.input_default, self.block.input_schema.jsonschema()- )+ for field_name in self.block.input_schema.get_credentials_fields():+ stripped_node.input_default.pop(field_name, None)- # Remove default secret value from secret input nodes- if (- stripped_node.block.block_type == BlockType.INPUT- and stripped_node.input_default.get("secret", False) is True- and "value" in stripped_node.input_default- ):- del stripped_node.input_default["value"]+ schema_props = self.block.input_schema.jsonschema().get("properties", {})+ for field_name, field_schema in schema_props.items():+ if (+ isinstance(field_schema, dict)+ and field_schema.get("secret", False) is True+ ):+ stripped_node.input_default.pop(field_name, None)- # Remove webhook infostripped_node.webhook_id = Nonereturn stripped_node- @staticmethod- def _filter_secrets_from_node_input(- input_data: BlockInput, schema: dict[str, Any] | None- ) -> BlockInput:- sensitive_keys = ["credentials", "api_key", "password", "token", "secret"]- field_schemas = schema.get("properties", {}) if schema else {}- result = {}- for key, value in input_data.items():- field_schema: dict | None = field_schemas.get(key)- if (field_schema and field_schema.get("secret", False)) or (- any(sensitive_key in key.lower() for sensitive_key in sensitive_keys)- # Prevent removing `secret` flag on input nodes- and type(value) is not bool- ):- # This is a secret value -> filter this key-value pair out- continue- elif isinstance(value, dict):- result[key] = NodeModel._filter_secrets_from_node_input(- value, field_schema- )- else:- result[key] = value- return result-class GraphBaseMeta(BaseDbModel):"""@@ -341,9 +320,9 @@ class BaseGraph(GraphBaseMeta):**{k: vfor k, v in p.generate_schema().items()- if k not in ["description", "default"]+ if k not in ["description", "default", "secret"]},- "secret": p.secret,+ "secret": False,# Default value has to be set for advanced fields."advanced": p.advanced and p.value is not None,"title": p.title or p.name,diff --git a/autogpt_platform/backend/backend/data/graph_test.py b/autogpt_platform/backend/backend/data/graph_test.pyindex db65647af0..f80dcf75ed 100644--- a/autogpt_platform/backend/backend/data/graph_test.py+++ b/autogpt_platform/backend/backend/data/graph_test.py@@ -12,6 +12,7 @@ import backend.api.features.store.model as storefrom backend.api.model import CreateGraphfrom backend.blocks._base import BlockSchema, BlockSchemaInputfrom backend.blocks.basic import StoreValueBlock+from backend.blocks.code_executor import ExecuteCodeBlockfrom backend.blocks.io import AgentInputBlock, AgentOutputBlockfrom backend.blocks.llm import LEGACY_MODEL_MAPPINGS, LlmModelfrom backend.data.graph import (@@ -19,6 +20,7 @@ from backend.data.graph import (GraphModel,Link,Node,+ NodeModel,get_graph,migrate_llm_models,validate_graph_execution_permissions,@@ -242,12 +244,14 @@ async def test_get_input_schema(server: SpinTestServer, snapshot: Snapshot):@pytest.mark.asyncio(loop_scope="session")async def test_clean_graph(server: SpinTestServer):"""- Test the stripped_for_export function that:- 1. Removes sensitive/secret fields from node inputs- 2. Removes webhook information- 3. Preserves non-sensitive data including input block values+ `stripped_for_export`:+ 1. Drops the entire value of any field the block schema declares as a+ `CredentialsMetaInput` (importers must wire up their own credentials).+ 2. Drops the value of any field the schema marks `secret: true` via+ `SchemaField(secret=True)`.+ 3. Nulls out `webhook_id`.+ 4. Leaves every other field in `input_default` untouched."""- # Create a graph with input blocks containing both sensitive and normal datagraph = Graph(id="test_clean_graph",name="Test Clean Graph",@@ -258,100 +262,92 @@ async def test_clean_graph(server: SpinTestServer):input_default={"_test_id": "input_node","name": "test_input",- "value": "test value", # This should be preserved+ "value": "test value","description": "Test input description",},),- Node(- block_id=AgentInputBlock().id,- input_default={- "_test_id": "input_node_secret",- "name": "secret_input",- "value": "another value",- "secret": True, # This makes the input secret- },- ),Node(block_id=StoreValueBlock().id,input_default={- "_test_id": "node_with_secrets",+ "_test_id": "non_credentials_node","input": "normal_value","control_test_input": "should be preserved",- "api_key": "secret_api_key_123", # Should be filtered # pragma: allowlist secret # noqa- "password": "secret_password_456", # Should be filtered # pragma: allowlist secret # noqa- "token": "secret_token_789", # Should be filtered- "credentials": { # Should be filtered+ "api_key": "left_alone_now", # pragma: allowlist secret+ "credentials": {"id": "fake-github-credentials-id","provider": "github","type": "api_key",},- "anthropic_credentials": { # Should be filtered- "id": "fake-anthropic-credentials-id",- "provider": "anthropic",- "type": "api_key",- },},),],links=[],)- # Create graph and get modelcreate_graph = CreateGraph(graph=graph)created_graph = await server.agent_server.test_create_graph(create_graph, DEFAULT_USER_ID)- # Clean the graphcleaned_graph = await server.agent_server.test_get_graph(created_graph.id, created_graph.version, DEFAULT_USER_ID, for_export=True)- # Verify sensitive fields are removed but normal fields are preservedinput_node = next(n for n in cleaned_graph.nodes if n.input_default["_test_id"] == "input_node")-- # Non-sensitive fields should be preservedassert input_node.input_default["name"] == "test_input"- assert input_node.input_default["value"] == "test value" # Should be preserved now+ assert input_node.input_default["value"] == "test value"assert input_node.input_default["description"] == "Test input description"+ assert "secret" not in input_node.input_default- # Sensitive fields should be filtered out- assert "api_key" not in input_node.input_default- assert "password" not in input_node.input_default-- # Verify secret input node preserves non-sensitive fields but removes secret value- secret_node = next(+ non_credentials_node = next(nfor n in cleaned_graph.nodes- if n.input_default["_test_id"] == "input_node_secret"+ if n.input_default["_test_id"] == "non_credentials_node")- assert secret_node.input_default["name"] == "secret_input"- assert "value" not in secret_node.input_default # Secret default should be removed- assert secret_node.input_default["secret"] is True+ assert non_credentials_node.input_default["input"] == "normal_value"+ assert (+ non_credentials_node.input_default["control_test_input"]+ == "should be preserved"+ )+ assert non_credentials_node.input_default["api_key"] == "left_alone_now"+ assert non_credentials_node.input_default["credentials"] == {+ "id": "fake-github-credentials-id",+ "provider": "github",+ "type": "api_key",+ }- # Verify sensitive fields are filtered from nodes with secrets- secrets_node = next(- n- for n in cleaned_graph.nodes- if n.input_default["_test_id"] == "node_with_secrets"- )- # Normal fields should be preserved- assert secrets_node.input_default["input"] == "normal_value"- assert secrets_node.input_default["control_test_input"] == "should be preserved"- # Sensitive fields should be filtered out- assert "api_key" not in secrets_node.input_default- assert "password" not in secrets_node.input_default- assert "token" not in secrets_node.input_default- assert "credentials" not in secrets_node.input_default- assert "anthropic_credentials" not in secrets_node.input_default-- # Verify webhook info is removed (if any nodes had it)for node in cleaned_graph.nodes:assert node.webhook_id is None+def test_stripped_for_export_drops_declared_credentials_field():+ """A field the block schema declares as `CredentialsMetaInput` is dropped+ entirely on export, even when the rest of `input_default` is left alone."""+ node = NodeModel(+ id="n1",+ block_id=ExecuteCodeBlock().id,+ input_default={+ "credentials": {+ "id": "fake-e2b-credentials-id",+ "provider": "e2b",+ "type": "api_key",+ },+ "code": "print('hi')",+ },+ graph_id="g1",+ graph_version=1,+ webhook_id="wh-1",+ )++ stripped = node.stripped_for_export()++ assert "credentials" not in stripped.input_default+ assert stripped.input_default["code"] == "print('hi')"+ assert stripped.webhook_id is None++@pytest.mark.asyncio(loop_scope="session")async def test_access_store_listing_graph(server: SpinTestServer):"""diff --git a/autogpt_platform/backend/migrations/20260520120000_drop_io_block_secret_toggle/migration.sql b/autogpt_platform/backend/migrations/20260520120000_drop_io_block_secret_toggle/migration.sqlnew file mode 100644index 0000000000..9358f72377--- /dev/null+++ b/autogpt_platform/backend/migrations/20260520120000_drop_io_block_secret_toggle/migration.sql@@ -0,0 +1,26 @@+-- For AgentInput* / AgentOutput nodes where `constantInput.secret = true`,+-- drop both the `secret` key (no longer part of the block schema) and+-- the `value` key (the default value the user explicitly marked as+-- secret, which would otherwise become visible without the masking+-- toggle).+--+-- Block IDs below cover the AgentInput base block, every subclass+-- declared in `backend/blocks/io.py`, and the AgentOutput block.++UPDATE "AgentNode"+SET "constantInput" = "constantInput" - 'secret' - 'value'+WHERE "agentBlockId" IN (+ 'c0a8e994-ebf1-4a9c-a4d8-89d09c86741b', -- AgentInputBlock (base)+ '7fcd3bcb-8e1b-4e69-903d-32d3d4a92158', -- AgentShortTextInputBlock+ '90a56ffb-7024-4b2b-ab50-e26c5e5ab8ba', -- AgentLongTextInputBlock+ '96dae2bb-97a2-41c2-bd2f-13a3b5a8ea98', -- AgentNumberInputBlock+ '7e198b09-4994-47db-8b4d-952d98241817', -- AgentDateInputBlock+ '2a1c757e-86cf-4c7e-aacf-060dc382e434', -- AgentTimeInputBlock+ '95ead23f-8283-4654-aef3-10c053b74a31', -- AgentFileInputBlock+ '655d6fdf-a334-421c-b733-520549c07cd1', -- AgentDropdownInputBlock+ 'cbf36ab5-df4a-43b6-8a7f-f7ed8652116e', -- AgentToggleInputBlock+ '5603b273-f41e-4020-af7d-fbc9c6a8d928', -- AgentTableInputBlock+ 'd3b32f15-6fd7-40e3-be52-e083f51b19a2', -- AgentGoogleDriveFileInputBlock+ '363ae599-353e-4804-937e-b2ee3cef3da4' -- AgentOutputBlock+)+AND "constantInput"->'secret' = 'true'::jsonb;diff --git a/docs/integrations/block-integrations/basic.md b/docs/integrations/block-integrations/basic.mdindex 3fe8df3c40..20a25aef2d 100644--- a/docs/integrations/block-integrations/basic.md+++ b/docs/integrations/block-integrations/basic.md@@ -143,7 +143,6 @@ The block is part of the Agent Input family, allowing you to collect structured| title | The title of the input. | str | No || description | The description of the input. | str | No || advanced | Whether to show the input in the advanced section, if the field is not required. | bool | No |-| secret | Whether the input should be treated as a secret. | bool | No |### Outputs@@ -183,7 +182,6 @@ This is ideal when you want to constrain user input to a predefined set of choic| title | The title of the input. | str | No || description | The description of the input. | str | No || advanced | Whether to show the input in the advanced section, if the field is not required. | bool | No |-| secret | Whether the input should be treated as a secret. | bool | No || options | If provided, renders the input as a dropdown selector restricted to these values. Leave empty for free-text input. | List[Any] | No |### Outputs@@ -224,7 +222,6 @@ By default, the block outputs a file path string that other blocks can use to ac| title | The title of the input. | str | No || description | The description of the input. | str | No || advanced | Whether to show the input in the advanced section, if the field is not required. | bool | No |-| secret | Whether the input should be treated as a secret. | bool | No || base_64 | Whether produce an output in base64 format (not recommended, you can pass the string path just fine accross blocks). | bool | No |### Outputs@@ -265,7 +262,6 @@ You can configure which file types to display (documents, spreadsheets, presenta| title | The title of the input. | str | No || description | The description of the input. | str | No || advanced | Whether to show the input in the advanced section, if the field is not required. | bool | No |-| secret | Whether the input should be treated as a secret. | bool | No || allowed_views | Which views to show in the file picker (DOCS, SPREADSHEETS, PRESENTATIONS, etc.). | List["DOCS" \| "DOCUMENTS" \| "SPREADSHEETS" \| "PRESENTATIONS" \| "DOCS_IMAGES" \| "FOLDERS"] | No || allow_folder_selection | Whether to allow selecting folders. | bool | No |@@ -305,7 +301,6 @@ It accepts a value from the user, along with metadata such as name and descripti| title | The title of the input. | str | No || description | The description of the input. | str | No || advanced | Whether to show the input in the advanced section, if the field is not required. | bool | No |-| secret | Whether the input should be treated as a secret. | bool | No |### Outputs@@ -341,7 +336,6 @@ The block is ideal for collecting longer-form content like messages, description| title | The title of the input. | str | No || description | The description of the input. | str | No || advanced | Whether to show the input in the advanced section, if the field is not required. | bool | No |-| secret | Whether the input should be treated as a secret. | bool | No |### Outputs@@ -381,7 +375,6 @@ This is useful when you need numeric parameters like quantities, counts, limits,| title | The title of the input. | str | No || description | The description of the input. | str | No || advanced | Whether to show the input in the advanced section, if the field is not required. | bool | No |-| secret | Whether the input should be treated as a secret. | bool | No |### Outputs@@ -421,7 +414,6 @@ It accepts an input value along with a name, description, and optional format st| format | The format string to be used to format the recorded_value. Use Jinja2 syntax. | str | No || escape_html | Whether to escape special characters in the inserted values to be HTML-safe. Enable for HTML output, disable for plain text. | bool | No || advanced | Whether to treat the output as advanced. | bool | No |-| secret | Whether the output should be treated as a secret. | bool | No |### Outputs@@ -458,7 +450,6 @@ The input displays as a standard text field and passes the entered text to downs| title | The title of the input. | str | No || description | The description of the input. | str | No || advanced | Whether to show the input in the advanced section, if the field is not required. | bool | No |-| secret | Whether the input should be treated as a secret. | bool | No |### Outputs@@ -498,7 +489,6 @@ The table input is ideal for structured data entry where users need to provide m| title | The title of the input. | str | No || description | The description of the input. | str | No || advanced | Whether to show the input in the advanced section, if the field is not required. | bool | No |-| secret | Whether the input should be treated as a secret. | bool | No || column_headers | Column headers for the table. | List[str] | No |### Outputs@@ -539,7 +529,6 @@ The time picker provides a user-friendly interface for selecting times without r| title | The title of the input. | str | No || description | The description of the input. | str | No || advanced | Whether to show the input in the advanced section, if the field is not required. | bool | No |-| secret | Whether the input should be treated as a secret. | bool | No |### Outputs@@ -579,7 +568,6 @@ The toggle is ideal for binary choices like enabling features, confirming action| title | The title of the input. | str | No || description | The description of the input. | str | No || advanced | Whether to show the input in the advanced section, if the field is not required. | bool | No |-| secret | Whether the input should be treated as a secret. | bool | No |### Outputs