Skip to content

feat: experimental traffic analysis#2848

Draft
sobanieca-redocly wants to merge 16 commits into
mainfrom
feat/traffic-analysis
Draft

feat: experimental traffic analysis#2848
sobanieca-redocly wants to merge 16 commits into
mainfrom
feat/traffic-analysis

Conversation

@sobanieca-redocly

@sobanieca-redocly sobanieca-redocly commented Jun 3, 2026

Copy link
Copy Markdown

What/Why/How?

PoC for traffic analysis so we can check drift between real traffic and specified OAD.

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

Medium Risk
Large new CLI surface with dynamic plugin imports and a local reverse proxy that forwards real HTTP traffic; security rules are heuristic and experimental rather than core auth changes.

Overview
Adds two experimental CLI commands: drift compares recorded HTTP traffic to an OpenAPI description (or generates OpenAPI 3.1 from traffic when --api is omitted), and proxy forwards live requests to an upstream while writing a HAR and optionally running the same checks in real time.

drift ingests HAR, Kong, Nginx/Apache JSON, and NDJSON (auto-detect or explicit format), normalizes exchanges, matches them to bundled OpenAPI operations, and runs pluggable rules—defaults cover undocumented routes, schema/parameter consistency (AJV), and security baselines; owasp-api-top10 is opt-in. Reports can be pretty, json, csv, or sarif; error-level findings exit with code 1. External --plugin / --traffic-plugin modules can extend rules and parsers.

proxy reuses the shared in-memory ValidationSession from drift, streams live findings, and prints a full drift report on shutdown. lint config output now skips mixing config-lint into csv/sarif single-document formats. E2E snapshots cover formats, generation, and validation scenarios.

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

@changeset-bot

changeset-bot Bot commented Jun 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fdc6bc1

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

This PR includes changesets to release 3 packages
Name Type
@redocly/cli Minor
@redocly/openapi-core 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

@sobanieca-redocly sobanieca-redocly changed the title feat: traffic analysis poc feat: experimental traffic analysis Jun 8, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 81.23% (🎯 81%) 7295 / 8980
🔵 Statements 80.59% (🎯 80%) 7582 / 9408
🔵 Functions 84.46% (🎯 84%) 1468 / 1738
🔵 Branches 72.85% (🎯 72%) 4934 / 6772
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/cli/src/types.ts 100% 100% 100% 100%
packages/cli/src/commands/lint.ts 94.54% 86.04% 100% 94.54% 91-93, 158, 192
Generated in workflow #10169 for commit fdc6bc1 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark (Lower is Faster)

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

@sobanieca-redocly

Copy link
Copy Markdown
Author

@cursor review

Comment thread packages/cli/src/commands/proxy/server.ts Outdated
Comment thread packages/cli/src/commands/drift/utils/http.ts
Comment thread packages/cli/src/commands/proxy/server.ts
Comment thread packages/cli/src/commands/drift/engine/runner.ts
Comment thread packages/cli/src/commands/drift/rules/builtins/security.ts
@sobanieca-redocly

Copy link
Copy Markdown
Author

@cursor review

Comment thread packages/cli/src/commands/proxy/server.ts
Comment thread packages/cli/src/commands/proxy/server.ts Outdated
Comment thread packages/cli/src/commands/proxy/index.ts Outdated
Comment thread packages/cli/src/commands/drift/openapi/matcher.ts Outdated
@sobanieca-redocly

Copy link
Copy Markdown
Author

@cursor review

Comment thread packages/cli/src/commands/proxy/server.ts Outdated
Comment thread packages/cli/src/commands/drift/rules/builtins/schema.ts
Comment thread packages/cli/src/commands/drift/rules/builtins/schema.ts
Comment thread packages/cli/src/commands/drift/openapi/loader.ts
@sobanieca-redocly

Copy link
Copy Markdown
Author

@cursor review

Comment thread packages/cli/src/commands/drift/index.ts
Comment thread packages/cli/src/commands/drift/log-formats/ndjson.ts Outdated
Comment thread packages/cli/src/commands/drift/engine/schema-validator.ts
Comment thread packages/cli/src/commands/drift/openapi/generator.ts
@sobanieca-redocly

Copy link
Copy Markdown
Author

@cursor review

Comment thread packages/cli/src/commands/drift/log-formats/helpers.ts Outdated
@sobanieca-redocly

Copy link
Copy Markdown
Author

@cursor review

Comment thread packages/cli/src/commands/proxy/index.ts
Comment thread packages/cli/src/commands/drift/log-formats/har.ts
Comment thread packages/cli/src/commands/drift/rules/builtins/schema.ts
@sobanieca-redocly

Copy link
Copy Markdown
Author

@cursor review

@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 and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

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 47e4b1e. Configure here.

Comment thread packages/cli/src/commands/drift/openapi/matcher.ts

- Starts a reverse proxy that forwards every request to an upstream `--target`
and records each request/response exchange into a HAR file.
- The HAR file is written incrementally (after each exchange) and flushed on

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

As mentioned during demo - do we want to keep this behavior for the first release? (this means proxy will be usable only for short lived processes like e2e tests etc.). In future we can introduce chunking (and give drift command option to read whole folder of traffic files). Eventually we can switch to ndjson format and append line by line.

- `--api <path>`: OpenAPI file or folder to validate against. Omit to generate.
- `--traffic-format <auto|har|kong|nginx-json|apache-json|ndjson>` (default: `auto`)
- `--format <pretty|json|csv|sarif>` (default: `pretty`)
- `--match-mode <strict-host|basepath>` (default: `strict-host`): how requests are located

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Since we add server option which seems more flexible maybe we should get rid of match-mode param at all? That way we will always use strict-host so we validate against OAD, but user may also override server.

Mutually exclusive with `--match-mode`: use `--match-mode` when the traffic URLs align
with the description `servers`, use `--server` to declare the actual server when they
do not.

@sobanieca-redocly sobanieca-redocly Jun 12, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

As presented during demo - shall we include ignore option for the first release? To avoid messages about unknown headers like x-caddy-authtoken etc.

Comment thread vitest.config.ts
'packages/**/__tests__/**/*',
'packages/cli/src/index.ts',
'packages/cli/src/utils/assert-node-version.ts',
'packages/cli/src/commands/drift/**',

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Is it fine if we ignore coverage for experimental commands? I would expect that source code there may change significantly over time after getting feedback on usage....

- missing required parameters/body,
- request/response schema mismatches,
- baseline security issues (opt-in OWASP API risk heuristics).
- When no spec is provided, infers an OpenAPI 3.1 description from the traffic.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Do we need to improve OAD generation option for the first release? Maybe we should explicitly require path to folder where OAD will be saved and implement more sophisticated schemas generation?

On the other hand - we may wait for feedback and do this in next iteration.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

As discussed in Slack - we will remove OAD generation in this PR.

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.

1 participant