Skip to content

fix: keep malformed arguments and account entries inside the error hierarchy - #260

Open
glebedel wants to merge 4 commits into
mainfrom
s2d2/audit-malformed-input
Open

glebedel wants to merge 4 commits into
mainfrom
s2d2/audit-malformed-input

Conversation

@glebedel

@glebedel glebedel commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What

  • StackOneTool._parse_arguments raises ToolArgumentsError ("Tool arguments for {tool} must have string keys") when the arguments dict has a non-string key, and StackOneToolSet.execute() raises ToolsetConfigError ("arguments must have string keys") for the same input.
  • StackOneToolSet._fetch_active_account_ids ignores GET /accounts entries that are not objects, and only treats a non-empty string id as an active account.

Why

Both paths could raise an AttributeError, which escapes the StackOneError hierarchy CLAUDE.md promises for every public method:

  • tool.execute({1: "x"}) reached _sanitise_header_arguments, which calls key.startswith("headers_") on every top-level key. The nested headers path already skipped non-string keys; the top level did not.
  • Discovery read each account with a.get(...), so a non-dict entry in the list crashed, and any truthy id (for example 5) was taken as an account id and sent as x-account-id. fetch_accounts() already skips such entries with isinstance guards when it records end users and providers; discovery now does the same.
Input Before After
tool.execute({1: "x"}) AttributeError: 'int' object has no attribute 'startswith' ToolArgumentsError
accounts ["junk", {"id": 5, "status": "active"}, {"id": "acc", "status": "active", ...}] AttributeError: 'str' object has no attribute 'get' discovers ["acc"]
accounts with only malformed entries, e.g. ["junk", None] AttributeError ToolsetConfigError: This API key has no linked accounts. ...

The two "must have string keys" messages are new and are not added to tests/vectors/messages.json, so the shared message vectors are unchanged.

How verified

  • Three new tests; all three fail on main with AttributeError and pass here.
  • uv run ruff check ., uv run ruff format --check ., uv run ty check stackone_ai examples: clean.
  • uv run pytest (Python 3.13, MCP mock via pnpm): 874 passed.

Gates (head f27f683)

Gate Result
Repo skills none in repo
/forge:forge ran on cd284d5: test docstrings now state the contract; re-run on f27f683: 4 comment lines, longest block 1, 0 copies
Security scan security-reviewer agent: no finding at confidence 70 or above. Aikido: 31 open issues on main (lockfile CVEs, workflow SAST, one old test-fixture secret), none on lines this PR changes
Codex security clean on e03e85a (job c8a37fd3) and f27f683 (job b2f55e81)
/security-review ran: secrets, input validation, transport and DoS items clean; the server-side items do not apply to an SDK
/code-review medium on cd284d5, 8 candidates. Fixed 4: entries that are not objects are no longer counted as accounts, a list of only such entries reads as "no linked accounts", toolset.execute() refuses non-string keys with ToolsetConfigError as its docstring promises, and the error says the keys must be strings. Declined 4: nested keys serialise through json.dumps as on main, the check stays at parse time (the contract every tool shares), the search/execute double parse is unchanged from main, and the test that asserted the old count is updated
CI green on f27f683: 10 pass, 3 skipped
Unresolved review threads 0

Requested by guillaume@stackone.com in Slack (repo audit thread)

🤖 Generated with Claude Code


Summary by cubic

Fixes two paths where malformed input crashed with AttributeError instead of raising a StackOneError.

  • Tool calls whose arguments dict has a non-string key now raise ToolArgumentsError (from tool.execute()) or ToolsetConfigError (from toolset.execute()) instead of crashing during header sanitising.
  • Account discovery now skips non-dict entries and non-string account ids in GET /accounts responses; malformed entries are left out of the inactive-account count, and a list of only such entries reads as "no linked accounts".

The two "must have string keys" messages are new and are not added to the shared message vectors.

Written for commit 4f3aeac. Summary will update on new commits.

View guided diff Turn on auto-fix

…erarchy

A tool call whose arguments dict has a non-string key reached header
sanitising and failed with an AttributeError on key.startswith(). It is
not a JSON object, so it now raises ToolArgumentsError with the existing
message, before any request.

Account discovery read each GET /accounts entry with .get() and took any
truthy id, so a non-dict entry raised AttributeError and a numeric id
became an account id. fetch_accounts() already skips such entries when it
records end users and providers; discovery now does the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
@glebedel glebedel self-assigned this Nov 10, 2026
s2d2-s1 and others added 2 commits November 11, 2026 00:34
…tracts

The two docstrings narrated the old failure ("failed with an AttributeError").
They now say what the code guarantees. No behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
A list of entries that are not objects now reads as no linked accounts, and the
inactive count leaves those entries out. toolset.execute() refuses non-string
argument keys with ToolsetConfigError, as its docstring promises, rather than
letting the inner execute tool raise under its own name, and the error says
the keys must be strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
@glebedel
glebedel requested a review from willleeney November 11, 2026 14:08
@glebedel

Copy link
Copy Markdown
Contributor Author

@willleeney a nudge on this one when you have a moment. StackOneTool._parse_arguments raises ToolArgumentsError ("Tool arguments for {tool} must have string keys") when the arguments dict has a non-string key, and StackOneToolSet.execute() raises ToolsetConfigError ("arguments must have string keys") for th

Why it should be a quick review: +49 -7 across 4 files, CI green on the current head, forge and /code-review already run, no open review threads. It only needs an approving review to merge.

This branch has not been deployed

No deployments
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.

2 participants