Fix CorpusReference visibility checks#2080
Conversation
Code ReviewThis PR patches an IDOR in 1.
|
…sibility #2080's CorpusReferenceService.visible_to_user added a target-visibility filter (correct for the corpusReferences GraphQL query, which exposes target_document). But the governance graph consumes references and ghosts invisible targets itself (the degrade-to-ghost contract in test_invisible_authority_target_degrades_to_external_ghost) — the target pre-filter dropped those references before the graph could degrade them. Split the visibility: add visible_to_user_by_source / for_corpus_by_source (corpus READ + visible source document, target NOT filtered) and point the governance graph at it. visible_to_user now builds on the source-only base plus the target filter, so its behaviour and the GraphQL surface are unchanged. The graph's existing per-endpoint checks drop hidden-source edges and degrade hidden targets to external ghost nodes.
Code Review — Fix CorpusReference visibility checksThis PR addresses a real IDOR/authorization bypass: the old Finding 1 — Data loss: structural annotations silently dropped from all surfaces
Fix: add a null guard — Finding 2 — Data loss: target structural annotations silently filter the reference out
The same Fix: Finding 3 — IDOR gap:
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Motivation
CorpusReferencerows based only on parent-corpus visibility which could expose source/target documents, annotations, and related corpus metadata to callers who lack document-level access.Description
opencontractserver/enrichment/services/corpus_reference_service.pyto filtervisible_to_userby readable corpora and readable documents and to require thatsource_annotation's document and anytarget_document/target_annotation/target_corpusare visible to the requesting user.Q+Documentimports and expand the service docstring to document the enforced MIN-permission semantics.opencontractserver/tests/test_corpus_reference_model.py(CorpusReferenceVisibilityTests) that assert references are filtered out when the source document, target document, or target corpus is not visible and that references remain when all edges are visible.Testing
python -m py_compile opencontractserver/enrichment/services/corpus_reference_service.py opencontractserver/tests/test_corpus_reference_model.pywhich succeeded.git diff --checkwhich reported no problems.pytest opencontractserver/tests/test_corpus_reference_model.py -qbut test execution was blocked by a runtime dependency error (ModuleNotFoundError: No module named 'django'), so the new tests could not be executed in this environment.Codex Task