Repository navigation
feat(openapi): filter the OpenAPI document per caller, cached per grant set (0.9.0) - #26
Merged
Merged
Conversation
…om OperationGrantChecker [*] The grant decision on an operation's security expression moves into a switch-free evaluator so a second consumer can use it under its own switch. OperationGrantChecker delegates to it; constructor, service definition and Hydra behaviour are unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… access_control [*] A decorator of api_platform.openapi.factory that runs last removes every operation the current token could not execute, judged by the operation's security expression and the firewall's access_control rule for its path and method. Paths without a remaining operation disappear, unreachable component schemas and unused tags are pruned, securitySchemes and the global security stay for every caller. On by default (openapi.filter_operations_by_security); object-dependent operations are listed by default (openapi.show_object_dependent_operations). Without a request (console) the document stays unfiltered. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… docs response private [*] The unfiltered document is cached per base URL and spec version, the filtered one per grant set, in a pool derived from cache.system and keyed by the container build id; openapi.cache_lifetime (default 3600, 0 disables) bounds an entry. A request with filter_tags bypasses the cache. A late kernel.response listener forces Cache-Control: private and adds Vary: Authorization on the OpenAPI and Swagger UI responses; /api/docs.jsonld is untouched. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A reusable building block under src/Test that, per configured caller, reads the OpenAPI document and calls every documented operation: a 403 on a documented operation is a violation. Only reading methods are called by default; writing methods need an explicit opt-in because they execute real requests in the app's test environment. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…, fix the Swagger UI 500 [*] Kernel tests with SecurityBundle cover callers, path mapping against the real document build, decorator order, object-dependent operations, pruning, the cache per grant set, response headers and the console export. Swagger UI on a resource URL whose operation the filtered document hides although the request is allowed answered 500; a decorator of api_platform.swagger_ui.processor now renders it without a pre-selected operation. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
README section for the OpenAPI filter and the guard test, CHANGELOG entry with the consumer actions. Part of issue #21. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of #21 (OpenAPI part; the Hydra documentation
/api/docs.jsonldfollows in a later release, the issue stays open).The OpenAPI document (
/api/docs.jsonopenapi, Swagger UI) is filtered per caller: an operation is listed only if both itssecurityexpression and the firewall'saccess_controlrule for its path and method allow the current token. On by default, release0.9.0.refactor: switch-freeOperationSecurityEvaluatorextracted fromOperationGrantChecker; Hydra behaviour, constructor and service definition unchanged, existing tests untouched.SecurityFilteredOpenApiFactorydecoratesapi_platform.openapi.factoryat priority-1000(outermost). Denied operations and empty paths are removed, schemas that became unreachable and unused tags are pruned;components.securitySchemesand the globalsecuritystay for every caller. Paths without an API Platform operation are decided byaccess_controlalone. Without a request (console export) the document is unfiltered.request, a throwing access checker, missing expression-language or security component hide operations that carry an expression. Object-dependent operations are listed by default (openapi.show_object_dependent_operations).cache.system, keyed by the container build id,openapi.cache_lifetime(default 3600,0disables);filter_tagsbypasses it.Cache-Control: privateandVary: Authorizationon the OpenAPI and Swagger UI responses;/api/docs.jsonlduntouched.src/Test(OpenApiGuardTestCase,OpenApiGuardTrait): no documented operation may answer 403 for a configured caller. Reading methods only by default.Consumer action
symfony/security-bundleorsymfony/expression-languagelose operations carrying asecurityexpression from the document until they switch the filter off.api_platform.openapi.factorymust stay at a priority above-1000.openapi.filter_operations_by_security: falserestores the previous document, registers none of the new services and changes no header.Test plan
^3.0is allowed by the constraint, only 4.x is installed and tested)🤖 Generated with Claude Code