Skip to content

feat: add security-scopes-defined rule#2951

Open
DmitryAnansky wants to merge 3 commits into
mainfrom
feat/security-scopes-defined-rule
Open

feat: add security-scopes-defined rule#2951
DmitryAnansky wants to merge 3 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
Additive lint rule and preset defaults (warn in recommended); no runtime auth or API behavior changes, though users may see new warnings on existing specs.

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, with typo suggestions via getSuggest.

OpenAPI 2.x/3.x and AsyncAPI 2.6 use a shared implementation that walks SecurityRequirement entries and compares against flow scopes (OAS3) or top-level scopes (OAS2). AsyncAPI 3.0 gets a dedicated rule that validates scheme scopes against flow availableScopes. Non-oauth2 schemes and missing schemes are skipped (the latter remain security-defined’s job).

Optional requireScopes enforces at least one scope on OAuth2 requirements (or on AsyncAPI 3 schemes). The rule is wired into OAS2/OAS3/Async2/Async3 rule indexes, typed rule IDs, and preset configs: warn in recommended, error in recommended-strict and all, off in minimal and spec. Docs, sidebar, changeset, and config test snapshots are updated accordingly.

Reviewed by Cursor Bugbot for commit bbf70aa. 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: bbf70aa

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 70.52% (🎯 69%) 7818 / 11086
🔵 Statements 70.21% (🎯 69%) 8138 / 11590
🔵 Functions 74.96% (🎯 73%) 1572 / 2097
🔵 Branches 62.07% (🎯 61%) 5275 / 8498
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 93.33% 71.42% 100% 100% 9
packages/core/src/rules/common/security-scopes-defined.ts 100% 83.33% 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 #10764 for commit bbf70aa 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.00x ± 0 ▓ 1.00x (Fastest)
cli-next ▓ 1.00x (Fastest) ▓ 1.00x (Fastest) ▓ 1.02x ± 0.01

@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
Co-authored-by: Jacek Łękawa <164185257+JLekawa@users.noreply.github.com>

@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.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bbf70aa. Configure here.

reference: 'https://redocly.com/docs/cli/rules/common/security-scopes-defined',
});
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

requireScopes flags unused AsyncAPI schemes

Medium Severity

With requireScopes enabled, the AsyncAPI 3 rule reports every oauth2 SecurityScheme that lacks scopes, including unused entries under components. The OAS implementation and the option docs only require scopes on actual security usages, so unused component schemes become false positives.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit bbf70aa. Configure here.

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.

2 participants