Skip to content

feat(jsonld): filter the Entrypoint context per caller (0.11.0) - #28

Merged
schmunk42 merged 4 commits into
masterfrom
feature/utils-context-filter
Dec 2, 2026
Merged

schmunk42 merged 4 commits into
masterfrom
feature/utils-context-filter

Conversation

@schmunk42

Copy link
Copy Markdown
Member

Summary

The last discovery document of #21 follows the per-caller filter: the JSON-LD context of the entrypoint, /api/contexts/Entrypoint.

  • Entrypoint context filtered per caller (EntrypointContextFilter, decorating api_platform.jsonld.context_builder): /api/contexts/Entrypoint (with and without .jsonld) contains exactly the resource keys whose link the JSON-LD entrypoint /api shows the same caller, plus @vocab and hydra. The allowed keys come from the filtered JSON-LD entrypoint normalizer, so page and context share one decision and cannot drift apart. Fails closed: without the normalizer, without a request, or when the decision throws, only the base entries remain.
  • Cache headers: the filtered Entrypoint context is Cache-Control: private with Vary: Authorization, also under a public cache configuration.
  • Fixed: ETag of the filtered Hydra documentation. API Platform computed the ETag of /api/docs.jsonld from the unfiltered body before the filter listener replaced it, so callers with different documents shared one ETag. The listener now recomputes it from the final body when the response carries one.
  • README and CHANGELOG 0.11.0.

No configuration key was added; discovery.filter_operations_by_security: false restores API Platform's behaviour.

Deliberately unfiltered

The contexts of the resource classes (/api/contexts/<ShortName>), Error and ConstraintViolationList keep API Platform's content and headers and answer 200 also for a class the caller sees in no discovery document: a visible response may embed an object of a hidden class, and a JSON-LD client then needs that context. A class context therefore still names the property names of its class and reveals its existence.

Observable break

The Entrypoint context is smaller than API Platform's for every caller, also for one with all rights: resources without a link on /api have no key, and neither have error and constraintViolation. See the consumer actions in the CHANGELOG.

Tests

791 tests green locally (API Platform 4.4.10, PHP 8.4). New kernel and unit tests for the context per caller, the fail-closed cases, untouched class contexts, headers and ETags; the regression test for the Hydra ETag fails on 0.10.0.

🤖 Generated with Claude Code

Closes #21

schmunk42 and others added 4 commits December 2, 2026 12:44
/api/contexts/Entrypoint now names exactly the resources whose link the
JSON-LD entrypoint /api shows the same caller, plus @vocab and hydra.
A decorator of the JSON-LD context builder takes the allowed keys from
the filtered entrypoint normalizer, so page and context share one
decision. It fails closed: without the normalizer, or when it throws,
only the base entries remain. Class contexts, Error and
ConstraintViolationList stay unfiltered.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The per-caller /api/contexts/Entrypoint now gets Cache-Control: private
and Vary: Authorization like the other filtered discovery documents,
also under a public cache configuration. Class contexts, Error and
ConstraintViolationList keep the headers of API Platform. Kernel tests
pin that the ETag of the context belongs to the filtered body.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…the filtered body [*]

API Platform computes the ETag from the unfiltered documentation before
the filter listener replaces the body, so callers with different
documents shared one ETag and a conditional request could confirm
foreign content. The listener now recomputes the ETag (xxh3, strong)
from the final body whenever the response already carries one;
with cache_headers.etag: false none is added.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
README: which JSON-LD context is filtered, which are not and why, cache
headers and ETags of the filtered documents. CHANGELOG 0.11.0 with the
consumer actions.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@schmunk42
schmunk42 merged commit 0ad365c into master Dec 2, 2026
1 check 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.

OpenAPI/Hydra docs: filter operations by the current token, cached per grant set

1 participant