Skip to content

Reject graph descriptors without an object id - #1425

Merged
tomchop merged 1 commit into
yeti-platform:mainfrom
cristianchiriac:reject-empty-graph-id
Oct 25, 2026
Merged

tomchop merged 1 commit into
yeti-platform:mainfrom
cristianchiriac:reject-empty-graph-id

Conversation

@cristianchiriac

Copy link
Copy Markdown
Contributor

Fixes #1414.

check_id_descriptor() checks that a source/target has exactly one / and that the type is in GRAPH_TYPE_MAPPINGS, but not that there is anything after the slash. "indicators/" passes validation, so the handler calls .get(""), and ArangoDB rejects the empty key with DocumentGetError (HTTP 404, ERR 1203) instead of returning None. The error escapes the handler and the client gets a 500.

The same validator is used by GraphSearchRequest, so POST /api/v2/graph/search with "source": "observables/" hits the same path.

Change

check_id_descriptor() now also rejects an empty id, so both endpoints answer 422 (source is missing the object id) before touching the database. The two .get() calls in the handlers are unchanged.

Verification

Against ArangoDB 3.11 and Redis from extras/docker/dev/docker-compose.yaml, with the environment from unittests.yml:

  • New tests test_add_link_missing_id (empty source id, empty target id) and test_get_neighbors_missing_id. On main both fail with arango.exceptions.DocumentGetError: [HTTP 404][ERR 1203] expecting GET /_api/document/<collection>/<key>; with the fix they pass.
  • pytest tests/apiv2/graph.py: 28 passed; pytest tests/apiv2: 247 passed.
  • ruff check and ruff format --check on the changed files pass.

check_id_descriptor() accepted "indicators/", so /graph/add and
/graph/search called .get("") and ArangoDB's DocumentGetError
escaped as a 500. Validate that the id part is non-empty so both
endpoints answer 422.

Fixes #1414.

@tomchop tomchop left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

An empty id reaching ArangoDB as a key was a 500; a 422 before the database is touched is right. CI green on 51daf83. Thanks!

@tomchop
tomchop merged commit 8b80c1a into yeti-platform:main Oct 25, 2026
5 checks passed
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.

POST /api/v2/graph/add returns 500 for a descriptor with an empty id

2 participants