Skip to content

fix: validate document keys before they reach request URLs - #3

Merged
thorwhalen merged 2 commits into
masterfrom
validate-document-keys
Sep 22, 2026
Merged

thorwhalen merged 2 commits into
masterfrom
validate-document-keys

Conversation

@thorwhalen

@thorwhalen thorwhalen commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Closes #2

What changes

  • New validate_document_key(key); ArangoDbPersister._make_key runs every joined key through it. A key must match ArangoDB's document-key alphabet (A-Za-z0-9_-:.@()+,=;$!*'), be 1–254 bytes, and not be . or ..; otherwise KeyError is raised before anything reaches the backend (reads, deletes and writes), so s[k] / s.get(k, d) behave like a missing key.
  • % is excluded from the alphabet even though ArangoDB allows it: pyArango does not encode keys in URLs and the server percent-decodes the path, so an encoded separator would bring back the same problem. Such keys did not round-trip correctly before either.
  • Tests in arangodol/tests/test_keys.py (no server needed).

CI

Master CI was red: test_arangodb.py and the class doctests connect to a local ArangoDB server at import/collection time. They are now skipped when no server is reachable (arangodol/tests/_live_server.py, root conftest.py), and docsrc/ is excluded from test collection. wads ci-local passes on 3.10 and 3.12 (live-server tests skipped; they were not run).

Review

Independent refute-review by a sub-agent: no blockers. Applied: __setitem__ validates the key before any backend call, clearer comment on why % is excluded, more rejection cases and a test that invalid keys never reach the backend. Noted, not changed: db_name/collection_name are also unescaped in URLs (configuration, not user data); class doctests still import the old py2store path and are skipped without a live server.

Compatibility

Valid ArangoDB keys are unaffected. No fleet dependents.

🤖 Generated with Claude Code

thorwhalen and others added 2 commits September 22, 2026 16:11
Keys are placed into pyArango document URLs unencoded. `_make_key` now
checks the joined key against ArangoDB's document-key alphabet (minus `%`,
which the server would percent-decode), rejects `.`/`..` and keys over 254
bytes, and raises KeyError otherwise. New public helper:
`validate_document_key`.

CI: live-server tests and doctests are skipped when no ArangoDB server is
reachable (they previously errored at collection), and docsrc/ is excluded
from test collection.

Closes #2

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@thorwhalen
thorwhalen merged commit 51dbbcc into master Sep 22, 2026
12 checks passed
@thorwhalen
thorwhalen deleted the validate-document-keys branch September 22, 2026 16:15
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.

Validate document keys before they reach the URL

1 participant