feat: add security-scopes-defined rule#2951
Open
DmitryAnansky wants to merge 2 commits into
Open
Conversation
🦋 Changeset detectedLatest commit: ed1ed08 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Performance Benchmark (Lower is Faster)
|
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.
What/Why/How?
Added security-scopes-defined rule.
It supports OpenAPI 2.0/3.x and AsyncAPI 2.6/3.0, suggests the closest defined scope for typos, and has an opt-in
requireScopesoption that requires OAuth2 security requirements to list at least one scope.Reference
Testing
Screenshots (optional)
Check yourself
Security
Note
Low Risk
Additive lint rule and preset defaults only; no runtime auth or API behavior changes, though recommended rulesets may surface new warnings on existing specs.
Overview
Adds a new built-in lint rule
security-scopes-definedthat validates OAuth2 scope names against what is declared in security schemes.For OpenAPI 2.x/3.x and AsyncAPI 2.6, scopes referenced in security requirements must exist in the scheme’s declared scopes (across flows where applicable). AsyncAPI 3.0 uses a dedicated implementation that checks scheme
scopesagainst flowavailableScopes. Non-oauth2schemes and missing scheme references are skipped (delegated tosecurity-defined). Undefined scopes get typo suggestions viagetSuggest; optionalrequireScopescan require at least one scope on OAuth2 requirements (or on AsyncAPI 3 schemes).The rule is wired into OAS2/OAS3/Async2 rule sets (shared common rule) and Async3 (separate visitor), registered in built-in rule ID types, and enabled as
warninrecommended/errorinrecommended-strictandall,offinminimalandspec. Docs, sidebar, ruleset templates, changeset, and snapshot tests are updated accordingly.Reviewed by Cursor Bugbot for commit ed1ed08. Bugbot is set up for automated code reviews on this repo. Configure here.