Skip to content

feat: add security-scopes-defined rule#2951

Merged
DmitryAnansky merged 6 commits into
mainfrom
feat/security-scopes-defined-rule
Jul 21, 2026
Merged

feat: add security-scopes-defined rule#2951
DmitryAnansky merged 6 commits into
mainfrom
feat/security-scopes-defined-rule

Conversation

@DmitryAnansky

@DmitryAnansky DmitryAnansky commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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 requireScopes option that requires OAuth2 security requirements to list at least one scope.

Reference

Testing

Screenshots (optional)

Check yourself

  • This PR follows the contributing guide
  • All new/updated code is covered by tests
  • Core code changed? - Tested with other Redocly products (internal contributions only)
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update has been considered

Security

  • The security impact of the change has been considered
  • Code follows company security practices and guidelines

Note

Low Risk
Read-only spec linting with no runtime auth behavior; recommended warn may surface new findings on existing APIs with mismatched OAuth2 scopes.

Overview
Adds a new built-in lint rule security-scopes-defined that flags OAuth2 scopes used in security requirements when they are not declared on the corresponding security scheme. It is wired into OpenAPI 2.x/3.x and AsyncAPI 2.6/3.0 rule sets, with a dedicated AsyncAPI 3.0 visitor that matches scopes on the scheme against availableScopes in flows (AsyncAPI 3’s model).

The rule resolves $ref’d flows when building the allowed scope list, skips non-oauth2 schemes and undefined schemes (left to security-defined), and can suggest a close declared scope for typos. Optional requireScopes enforces at least one scope on OAuth2 requirements (OAS/Async2) or on referenced schemes (Async3).

Recommended presets enable it at warn ( error in recommended-strict / all ); minimal / spec keep it off. Docs, sidebar, ruleset templates, config snapshots, and unit tests are updated accordingly.

Reviewed by Cursor Bugbot for commit 4b709a5. Bugbot is set up for automated code reviews on this repo. Configure here.

@DmitryAnansky DmitryAnansky self-assigned this Jul 16, 2026
@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4b709a5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@redocly/openapi-core Minor
@redocly/cli Minor
@redocly/respect-core Minor

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

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 71.97% (🎯 69%) 8676 / 12055
🔵 Statements 71.65% (🎯 69%) 9027 / 12598
🔵 Functions 76.63% (🎯 73%) 1719 / 2243
🔵 Branches 63.48% (🎯 61%) 5844 / 9205
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/config/all.ts 100% 100% 100% 100%
packages/core/src/config/minimal.ts 100% 100% 100% 100%
packages/core/src/config/recommended-strict.ts 100% 100% 100% 100%
packages/core/src/config/recommended.ts 100% 100% 100% 100%
packages/core/src/config/spec.ts 100% 100% 100% 100%
packages/core/src/rules/async2/index.ts 100% 100% 100% 100%
packages/core/src/rules/async3/index.ts 100% 100% 100% 100%
packages/core/src/rules/async3/security-scopes-defined.ts 90% 70% 100% 100% 15, 51, 65
packages/core/src/rules/common/security-scopes-defined.ts 100% 82.14% 100% 100%
packages/core/src/rules/oas2/index.ts 100% 100% 100% 100%
packages/core/src/rules/oas3/index.ts 100% 100% 100% 100%
packages/core/src/types/redocly-yaml.ts 92.92% 84.9% 100% 92.7% 419, 451, 457, 501-508, 510, 669-674, 677-682
Generated in workflow #10795 for commit 4b709a5 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark (Lower is Faster)

CLI Version Bundle Lint Check Config
cli-latest ▓ 1.01x ± 0.01 ▓ 1.01x ± 0.01 ▓ 1.01x ± 0.01
cli-next ▓ 1.00x (Fastest) ▓ 1.00x (Fastest) ▓ 1.00x (Fastest)

@DmitryAnansky
DmitryAnansky requested a review from tatomyr July 17, 2026 12:16
@DmitryAnansky
DmitryAnansky marked this pull request as ready for review July 17, 2026 12:52
@DmitryAnansky
DmitryAnansky requested review from a team as code owners July 17, 2026 12:52
Comment thread .changeset/security-scopes-defined-rule.md Outdated
Comment thread docs/@v2/rules/common/security-scopes-defined.md Outdated
Comment thread packages/core/src/rules/async3/security-scopes-defined.ts
@DmitryAnansky
DmitryAnansky force-pushed the feat/security-scopes-defined-rule branch from 52d8436 to 1c1ae4b Compare July 21, 2026 10:07

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1c1ae4b. Configure here.

Comment thread packages/core/src/rules/common/security-scopes-defined.ts
@DmitryAnansky
DmitryAnansky merged commit 233026f into main Jul 21, 2026
46 of 47 checks passed
@DmitryAnansky
DmitryAnansky deleted the feat/security-scopes-defined-rule branch July 21, 2026 13:21
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.

3 participants