Skip to content

fix: validate security middleware capabilities - #1225

Merged
kang-heewon merged 5 commits into
trunkfrom
fix/1174-security-middleware-markers
Jul 5, 2026
Merged

fix: validate security middleware capabilities#1225
kang-heewon merged 5 commits into
trunkfrom
fix/1174-security-middleware-markers

Conversation

@kang-heewon

@kang-heewon kang-heewon commented Jul 5, 2026

Copy link
Copy Markdown
Member

Fixes #1174.

Summary

  • Replaces HTTP security middleware source-text detection with explicit capability metadata for built-in, wrapped, and custom middleware.
  • Adds public marker helpers for declaring, reading, and checking security-headers, cors, body-limit, and rate-limit capabilities, with invalid runtime values reported as CROCO_HTTP_SECURITY_002.
  • Keeps bootstrap validation marker-only so minified built-ins pass and source-spoofed unmarked middleware fails with CROCO_HTTP_SECURITY_001.
  • Updates transport README, generated-app fixture guidance, diagnostics, Problem registry, public API snapshot, generated API docs, strict baseline line positions, and release metadata.

Verification

  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm --filter @croco/transports-http exec vitest run src/tests/SecurityMiddlewareMarker.spec.ts src/tests/CrocoApp.spec.ts --reporter=verbose - passed, 57 tests.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm --filter @croco/transports-http test - passed, 192 tests.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm --filter @croco/transports-http typecheck - passed.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm --filter @croco/transports-http... build - passed.
  • ASTRO_TELEMETRY_DISABLED=1 COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm --filter @croco/docs docs:build - passed, 3519 pages built.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm public-api:check - passed.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm problem-registry:check - passed, 414 codes.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm check - passed.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm --filter create-croco-app... build - passed.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm --filter create-croco-app exec vitest run src/tests/templates-build.spec.ts src/tests/e2e-generation.spec.ts --reporter=verbose - passed, 26 tests.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm changeset-required:check -- --base origin/trunk --head HEAD - passed.
  • git diff --check and git diff --cached --check - passed.
  • Pre-push hook test - passed, 225/225 Turbo tasks.
  • Pre-push hook typecheck - passed, 224/224 Turbo tasks.

Self-review gates

  • Correctness/regression: PASS. Built-in middleware, source-hidden/minified built-ins, wrappers that copy capabilities, and custom declared middleware bootstrap successfully; source-spoofed unmarked middleware is rejected.
  • API/security/compatibility/release: PASS. Public marker APIs are documented in generated API docs, invalid runtime capability values use CROCO_HTTP_SECURITY_002, CROCO_HTTP_SECURITY_001 keeps legacy code metadata, and a patch changeset is included.
  • Maintainability/minimality: PASS. The change stays within the existing transport marker/validation surface, generated docs/registries, and focused tests without adding dependencies.

Review and QA

  • Code review: PASS, no blockers.
  • Verification review: PASS, no acceptance gaps.
  • Architecture review: initial blockers for runtime helper validation and generated API docs were fixed; re-review returned CLEAR.

Notes

  • The first normal push attempt exposed a transient @croco/protocols-trpc declaration build race while @croco/problems-core dist declarations were being regenerated. The failing package build passed directly afterward, and the second normal push completed the full pre-push hook successfully without bypassing hooks.

Summary by CodeRabbit

  • New Features
    • HTTP λ³΄μ•ˆ 미듀웨어 검증이 μ†ŒμŠ€ ν…μŠ€νŠΈκ°€ μ•„λ‹Œ λͺ…μ‹œμ  capability 메타데이터λ₯Ό 기반으둜 λ™μž‘ν•˜λ„λ‘ κ°œμ„ λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
    • λ³΄μ•ˆ middleware capabilityλ₯Ό μ„ μ–ΈΒ·μ‘°νšŒΒ·κ²€μ‚¬ν•˜λŠ” 곡개 API 및 κ΄€λ ¨ λ¬Έμ„œκ°€ μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
  • Bug Fixes
    • λž˜ν•‘λœ 미듀웨어가 μ„ μ–Έλœ capabilityλ₯Ό μœ μ§€ν•˜λ„λ‘ 지원해 검증 μ‹€νŒ¨ κ°€λŠ₯성을 μ€„μ˜€μŠ΅λ‹ˆλ‹€.
    • μ§€μ›λ˜μ§€ μ•ŠλŠ” capability μž…λ ₯ μ‹œ 진단 μ½”λ“œμ™€ 였λ₯˜ 정보가 더 λͺ…ν™•ν•΄μ‘ŒμŠ΅λ‹ˆλ‹€.
  • Documentation
    • HTTP λ³΄μ•ˆ λΆ€νŠΈμŠ€νŠΈλž©, 문제 μ½”λ“œ/볡ꡬ κ°€μ΄λ“œ λ¬Έμ„œκ°€ μ΅œμ‹  λ™μž‘μ— 맞게 μ •κ΅ν™”Β·κ°±μ‹ λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

πŸ“ Walkthrough

Walkthrough

HTTP λ³΄μ•ˆ 미듀웨어 검증을 Function#toString() 기반 μ†ŒμŠ€ ν…μŠ€νŠΈ μΆ”λ‘ μ—μ„œ λͺ…μ‹œμ  capability 메타데이터 기반으둜 μ „ν™˜ν–ˆμŠ΅λ‹ˆλ‹€. SecurityMiddlewareMarker에 capability μ„ μ–Έ/쑰회/검증 APIλ₯Ό μΆ”κ°€ν•˜κ³ , CrocoApp의 λΆ€νŠΈμŠ€νŠΈλž© 검증 λ‘œμ§μ„ 이λ₯Ό μ‚¬μš©ν•˜λ„λ‘ κ΅μ²΄ν–ˆμœΌλ©°, μƒˆλ‘œμš΄ CROCO_HTTP_SECURITY_002 진단 μ½”λ“œμ™€ κ΄€λ ¨ λ¬Έμ„œ, export, ν…ŒμŠ€νŠΈλ₯Ό μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€.

Changes

λ³΄μ•ˆ 미듀웨어 Capability 기반 검증

Layer / File(s) Summary
Capability 마컀 API κ΅¬ν˜„
packages/transports-http/src/libs/middleware/SecurityMiddlewareMarker.ts
SecurityMiddlewareCapability νƒ€μž…, declareSecurityMiddlewareCapabilities/getSecurityMiddlewareCapabilities/hasSecurityMiddlewareCapability ν•¨μˆ˜, 메타데이터 μ €μž₯/생성 및 미지원 capability에 λŒ€ν•œ CROCO_HTTP_SECURITY_002 μ—λŸ¬ 처리λ₯Ό μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€.
CrocoApp λΆ€νŠΈμŠ€νŠΈλž© 검증 둜직 ꡐ체
packages/transports-http/src/libs/CrocoApp.ts
matches νŒλ³„ ν•¨μˆ˜ 기반 ν•„μˆ˜ 미듀웨어 검증을 μ œκ±°ν•˜κ³  capability ν•„λ“œμ™€ hasSecurityMiddlewareCapability 호좜둜 λˆ„λ½ 미듀웨어λ₯Ό νŒμ •ν•˜λ„λ‘ λ³€κ²½ν–ˆμŠ΅λ‹ˆλ‹€.
Public export 및 νšŒκ·€ ν…ŒμŠ€νŠΈ
packages/transports-http/src/index.ts, packages/transports-http/src/tests/CrocoApp.spec.ts, packages/transports-http/src/tests/SecurityMiddlewareMarker.spec.ts, public-api-surface.snapshot.json
μƒˆ capability APIλ₯Ό re-exportν•˜κ³  public API μŠ€λƒ…μƒ·μ„ κ°±μ‹ ν–ˆμœΌλ©°, λž˜ν•‘λœ 미듀웨어/μ†ŒμŠ€ μœ„μž₯ 미듀웨어/미지원 capability μ—λŸ¬μ— λŒ€ν•œ μ‹ κ·œ ν…ŒμŠ€νŠΈλ₯Ό μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€.
λ¬Έμ„œ, 진단 λ ˆμ§€μŠ€νŠΈλ¦¬ 및 changeset κ°±μ‹ 
.changeset/security-middleware-capabilities.md, packages/transports-http/README.md, packages/docs/src/content/docs/api/transports-http/..., docs/troubleshooting/diagnostics.md, docs/problem-code-registry.json, packages/docs/src/content/docs/en/reference/problem-recovery-cookbook.md, packages/create-croco-app/test-fixtures/templates/ssr-lambda/README.md.hbs, tsconfig/contract-strict.baseline.json
CROCO_HTTP_SECURITY_002 진단 μ½”λ“œμ™€ capability 기반 검증 μ•ˆλ‚΄λ₯Ό λ¬Έμ„œ/λ ˆμ§€μŠ€νŠΈλ¦¬/ν…œν”Œλ¦Ώ/patch changeset에 λ°˜μ˜ν–ˆμŠ΅λ‹ˆλ‹€.

Estimated code review effort: 3 (Moderate) | ~25 minutes

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed 제λͺ©μ΄ λ³΄μ•ˆ 미듀웨어 capability κ²€μ¦μœΌλ‘œμ˜ 핡심 변경을 κ°„κ²°ν•˜κ²Œ μš”μ•½ν•©λ‹ˆλ‹€.
Linked Issues check βœ… Passed capability 기반 검증, 곡개 API, ν…œν”Œλ¦Ώ/ν…ŒμŠ€νŠΈ/λ¬Έμ„œ 갱신이 μš”κ΅¬μ‚¬ν•­κ³Ό μΌμΉ˜ν•©λ‹ˆλ‹€.
Out of Scope Changes check βœ… Passed λ³€κ²½ 내역은 λͺ¨λ‘ λ³΄μ•ˆ 미듀웨어 검증 μ „ν™˜κ³Ό 그에 λ”°λ₯Έ λ¬Έμ„œΒ·ν…ŒμŠ€νŠΈΒ·λ©”νƒ€λ°μ΄ν„° 갱신에 ν•œμ •λ©λ‹ˆλ‹€.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1174-security-middleware-markers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

πŸ“Š Benchmark Results

βœ… All benchmarks passed

Benchmark p75 Threshold Baseline vs Baseline Status Notes
CrocoApp constructor 7.9ΞΌs 30.0ms 8.2ΞΌs -3.4% βœ… -
CrocoApp lambdaHandler (10 controllers) 317.5μs 50.0ms 258.4μs +22.9% ❌ -
Lambda cold-start simulation 436.3ΞΌs 80.0ms 418.1ΞΌs +4.4% βœ… -
Lambda cold-start with headers 398.8ΞΌs 80.0ms 369.7ΞΌs +7.9% βœ… -
Lambda cold-start with binary body 384.9ΞΌs 80.0ms 339.1ΞΌs +13.5% βœ… -
Lambda cold-start with query params 328.9ΞΌs 80.0ms 301.3ΞΌs +9.2% βœ… -
Lambda cold-start with authorizer context 314.3ΞΌs 80.0ms 299.8ΞΌs +4.8% βœ… -
Lambda cold-start realistic scenario 312.1ΞΌs 80.0ms 299.2ΞΌs +4.3% βœ… -
EventBusConfig.start (10 handlers) 1.4ΞΌs 10.0ms 1.4ΞΌs +0.6% βœ… -
EventPublisher.publishNow single event 1.7ΞΌs 2.0ms 1.7ΞΌs +1.8% βœ… -
DefaultHandlerResolver.resolve Γ— 10 0.1ΞΌs 5.0ms 0.1ΞΌs -11.2% βœ… -
Container.get singleton (cold) 70.2ΞΌs 5.0ms 70.3ΞΌs -0.1% βœ… -
Container.register Γ— 50 components 3.2ms 10.0ms 3.2ms +0.6% βœ… -
Container.validate (50 components) 3.5ms 20.0ms 3.4ms +4.7% βœ… -
Container.get singleton (warm) 1.7ΞΌs 500.0ΞΌs 1.6ΞΌs +1.2% βœ… -
TelemetryRuntime.init (lambda preset) 2.0ΞΌs 200.0ms 1.1ms -99.8% βœ… -
lambdaPreset config creation 1.4ΞΌs 2.0ms 1.4ΞΌs -0.6% βœ… -

Updated: 2026-07-05T12:09:17.485Z Β· Commit: 0a868ee

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

Actionable comments posted: 1

πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/transports-http/src/index.ts`:
- Around line 166-171: The new capability API export block is missing the same
leading Korean documentation comment used by the other public exports in this
file, so add a concise explanatory comment above the SecurityMiddlewareMarker
re-export to match the existing documentation pattern. Place it near the
exported symbols declareSecurityMiddlewareCapabilities,
getSecurityMiddlewareCapabilities, hasSecurityMiddlewareCapability, and
SecurityMiddlewareCapability so the block stays consistent with the adjacent
export sections.
πŸͺ„ Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 848b6af8-5a6e-4228-8ad4-6d96441663ec

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between cd98718 and e54c62d.

β›” Files ignored due to path filters (1)
  • packages/problems-core/src/generated/problem-code-registry.ts is excluded by !**/generated/**
πŸ“’ Files selected for processing (18)
  • .changeset/security-middleware-capabilities.md
  • docs/problem-code-registry.json
  • docs/troubleshooting/diagnostics.md
  • packages/create-croco-app/test-fixtures/templates/ssr-lambda/README.md.hbs
  • packages/docs/src/content/docs/api/problems-core/src/variables/CROCO_PROBLEM_CODE_REGISTRY.md
  • packages/docs/src/content/docs/api/transports-http/src/functions/declareSecurityMiddlewareCapabilities.md
  • packages/docs/src/content/docs/api/transports-http/src/functions/getSecurityMiddlewareCapabilities.md
  • packages/docs/src/content/docs/api/transports-http/src/functions/hasSecurityMiddlewareCapability.md
  • packages/docs/src/content/docs/api/transports-http/src/type-aliases/SecurityMiddlewareCapability.md
  • packages/docs/src/content/docs/en/reference/problem-recovery-cookbook.md
  • packages/transports-http/README.md
  • packages/transports-http/src/index.ts
  • packages/transports-http/src/libs/CrocoApp.ts
  • packages/transports-http/src/libs/middleware/SecurityMiddlewareMarker.ts
  • packages/transports-http/src/tests/CrocoApp.spec.ts
  • packages/transports-http/src/tests/SecurityMiddlewareMarker.spec.ts
  • public-api-surface.snapshot.json
  • tsconfig/contract-strict.baseline.json

Comment thread packages/transports-http/src/index.ts

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/docs/src/content/docs/en/reference/problem-recovery-cookbook.md (1)

369-372: πŸ“ Maintainability & Code Quality | 🟑 Minor | ⚑ Quick win

unsafeSkipSecurityValidation κ²½λ‘œλ„ 같이 적어 μ£Όμ„Έμš”.

ν˜„μž¬ μ•ˆλ‚΄λŠ” securityValidation: 'off'/CROCO_HTTP_SECURITY_VALIDATION=off만 μ„€λͺ…ν•΄μ„œ, λŸ°νƒ€μž„ λ©”μ‹œμ§€μ™€ PR λ²”μœ„μ— μžˆλŠ” unsafeSkipSecurityValidation: true λ§ˆμ΄κ·Έλ ˆμ΄μ…˜ κ²½λ‘œκ°€ λΉ μ§‘λ‹ˆλ‹€. λ‘˜ 쀑 ν•˜λ‚˜λ₯Ό μΆ”κ°€ν•˜κ±°λ‚˜, μ˜λ„μ μœΌλ‘œ μ œκ±°ν–ˆλ‹€λ©΄ λŒ€μ²΄ 절차λ₯Ό λͺ…μ‹œν•΄ μ£Όμ„Έμš”.

♻️ Suggested edit
- Use securityValidation: 'off' or `CROCO_HTTP_SECURITY_VALIDATION=off` only for explicit local
+ Use securityValidation: 'off', `unsafeSkipSecurityValidation: true`, or `CROCO_HTTP_SECURITY_VALIDATION=off` only for explicit local
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/docs/src/content/docs/en/reference/problem-recovery-cookbook.md`
around lines 369 - 372, The problem-recovery docs currently describe only the
securityValidation off path, but miss the runtime and migration path for
unsafeSkipSecurityValidation. Update the relevant reference section and any
linked guidance to explicitly mention unsafeSkipSecurityValidation: true
alongside securityValidation: 'off' and CROCO_HTTP_SECURITY_VALIDATION=off, or
clearly state the replacement procedure if that option was intentionally
removed. Use the surrounding tenant-core error/reference entries to locate the
affected documentation block.
πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/docs/src/content/docs/en/reference/problem-recovery-cookbook.md`:
- Around line 369-372: The problem-recovery docs currently describe only the
securityValidation off path, but miss the runtime and migration path for
unsafeSkipSecurityValidation. Update the relevant reference section and any
linked guidance to explicitly mention unsafeSkipSecurityValidation: true
alongside securityValidation: 'off' and CROCO_HTTP_SECURITY_VALIDATION=off, or
clearly state the replacement procedure if that option was intentionally
removed. Use the surrounding tenant-core error/reference entries to locate the
affected documentation block.

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: cccb97a5-1830-436f-a610-05637975b303

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between e54c62d and 5912030.

β›” Files ignored due to path filters (1)
  • packages/problems-core/src/generated/problem-code-registry.ts is excluded by !**/generated/**
πŸ“’ Files selected for processing (8)
  • docs/problem-code-registry.json
  • packages/docs/src/content/docs/api/problems-core/src/variables/CROCO_PROBLEM_CODE_REGISTRY.md
  • packages/docs/src/content/docs/en/reference/problem-recovery-cookbook.md
  • packages/transports-http/README.md
  • packages/transports-http/src/index.ts
  • packages/transports-http/src/tests/CrocoApp.spec.ts
  • public-api-surface.snapshot.json
  • tsconfig/contract-strict.baseline.json
πŸ’€ Files with no reviewable changes (1)
  • tsconfig/contract-strict.baseline.json

@kang-heewon
kang-heewon merged commit 1a209ad into trunk Jul 5, 2026
9 checks passed
@kang-heewon
kang-heewon deleted the fix/1174-security-middleware-markers branch July 5, 2026 12:48
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.

[transports-http] Replace security middleware source-string heuristics with explicit markers

1 participant