Skip to content

fix: two carry-over hotfixes (referencegrant name filter, anthropic tracing negative idx) - #10

Merged
pokabookinflab merged 2 commits into
mainfrom
feature/hotfix-triage
Jul 28, 2026
Merged

fix: two carry-over hotfixes (referencegrant name filter, anthropic tracing negative idx)#10
pokabookinflab merged 2 commits into
mainfrom
feature/hotfix-triage

Conversation

@pokabookinflab

@pokabookinflab pokabookinflab commented Jul 28, 2026

Copy link
Copy Markdown

Summary

Two carry-over defects flagged during earlier PR reviews (#4/#5/#6) that we consciously deferred as out-of-scope for those integration PRs. Both are upstream-inherited and low-blast-radius today, but real bugs — landing them explicitly so upstream can pick them up too.

1. internal/controller/referencegrant.go — honor ReferenceGrantTo.Name

Per Gateway API spec, ReferenceGrantTo.Name is optional. When set the grant is scoped to exactly that named target; when unset it acts as a wildcard for the group/kind. The controller was ignoring the field entirely, so a name-scoped grant

to:
  - group: aigateway.envoyproxy.io
    kind: AIServiceBackend
    name: safe-backend

silently allowed AIGatewayRoutes to reference any AIServiceBackend of that group/kind in the target namespace. Not what the grant author meant, and widens cross-namespace permission surface beyond the declared policy.

Thread targetName through validateReference → isReferenceGrantValid → matchesTo and add the name comparison at the leaf. Regression test covers wildcard (name unset), name match (allowed), name mismatch (denied).

2. internal/tracing/openinference/anthropic/messages.go — negative index panic

ContentBlockDelta / ContentBlockStop guarded the upper bound (idx < len(response.Content)) but not the lower bound. In Go, negative ints satisfy that condition, so a malformed / hostile SSE chunk with Index: -1 slipped through and panicked on the slice access below. Panics inside the tracing pipeline take the whole request down when OpenInference tracing is enabled.

Only ContentBlockStart had the non-negative guard. Extracted the shared check into isValidContentBlockIndex(idx) and applied it to every SSE index path. Upper bound (maxContentBlocks = 1000) preserved.

Regression test locks in the fix: Start(0) + Delta{-5} + Stop{-1} now completes cleanly.

Not in this PR

Third finding from the reviews — processor_impl.go auth handler receiving an empty body on the CONTINUE branch when a signature-based backend needs the actual current body — is deferred. Reproducing it needs GCP-Vertex-AI or AWS-Bedrock signing under specific request-shape conditions and warrants its own investigation; landing a speculative fix here would just add another moving part.

Verified

  • go build ./... && go vet ./...
  • golangci-lint run → 0 issues
  • go test ./internal/controller/... ./internal/tracing/openinference/anthropic/... passes including new regression cases

🤖 Generated with Claude Code

Summary by CodeRabbit

  • 버그 수정

    • 이름이 지정된 ReferenceGrant가 해당 리소스에만 정확히 적용되도록 검증을 강화했습니다.
    • 잘못된 스트리밍 콘텐츠 블록 인덱스로 인해 응답 처리 중 오류가 발생할 수 있는 문제를 방지했습니다.
    • 유효하지 않은 스트리밍 조각은 안전하게 건너뛰고 정상 콘텐츠를 유지합니다.
  • 테스트

    • ReferenceGrant 이름 일치 및 와일드카드 동작을 검증하는 테스트를 추가했습니다.
    • 음수 인덱스를 포함한 스트리밍 응답 처리 회귀 테스트를 추가했습니다.

pokabookinflab and others added 2 commits July 28, 2026 19:30
…ation

Per Gateway API spec, `ReferenceGrantTo.Name` is optional. When set, the grant
must apply only to that named target; when unset, it acts as a wildcard for
the group/kind. The controller was ignoring the field entirely, so a
name-scoped grant like

    to:
      - group: aigateway.envoyproxy.io
        kind: AIServiceBackend
        name: safe-backend

silently allowed AIGatewayRoutes to reference *any* AIServiceBackend of that
group/kind in the target namespace — not what the grant author meant. In
practice this widens cross-namespace permission surface beyond what the
policy declared.

Thread `targetName` through validateReference → isReferenceGrantValid →
matchesTo so the name comparison happens at the leaf. Wildcard behaviour
(name unset) is preserved.

Regression test added covering all three cases: name-unset wildcard,
name-matches (allowed), name-mismatch (denied).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…egatives

The upper-bound check on ContentBlockDelta/Stop was `idx < len(response.Content)`.
In Go, that condition is trivially satisfied by negative ints, so a malformed
or hostile upstream chunk with `Index: -1` slipped through and panicked on the
`response.Content[idx]` access below. The panic surfaces inside the tracing
pipeline (Anthropic messages recorder) and takes the request down when
OpenInference tracing is enabled.

Only ContentBlockStart had the non-negative guard. Extract the shared check
into `isValidContentBlockIndex(idx)` and apply it to every SSE index path
(Start / Delta / Stop). The upper bound (maxContentBlocks = 1000) is preserved
so a giant Index can't force a giant allocation either.

Regression test added: a chunk sequence with a valid Start followed by
ContentBlockDelta{Index:-5} and ContentBlockStop{Index:-1} now completes
without panic and produces the same content as if those events were absent.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@pokabookinflab
pokabookinflab merged commit 044b0d3 into main Jul 28, 2026
3 of 7 checks passed
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9b9fe763-2dd7-4f4d-a4b1-772c562f0c7f

📥 Commits

Reviewing files that changed from the base of the PR and between d10579c and 004403b.

📒 Files selected for processing (4)
  • internal/controller/referencegrant.go
  • internal/controller/referencegrant_test.go
  • internal/tracing/openinference/anthropic/messages.go
  • internal/tracing/openinference/anthropic/messages_test.go

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

Disabled knowledge base sources:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Walkthrough

ReferenceGrant가 대상 리소스 이름을 검증하도록 변경되었고, Anthropic 스트림 변환기가 잘못된 콘텐츠 블록 인덱스를 안전하게 건너뛰도록 보강되었다. 두 변경 모두 회귀 테스트가 추가되었다.

Changes

ReferenceGrant 이름 매칭

Layer / File(s) Summary
ReferenceGrant 이름 매칭과 테스트
internal/controller/referencegrant.go, internal/controller/referencegrant_test.go
ReferenceGrantTo.Name이 설정되면 대상 이름과 정확히 일치해야 하며, 미설정 시 와일드카드로 동작하도록 검증 경로와 테스트가 변경되었다.

Anthropic 콘텐츠 블록 인덱스 검증

Layer / File(s) Summary
콘텐츠 블록 인덱스 방어 로직과 회귀 테스트
internal/tracing/openinference/anthropic/messages.go, internal/tracing/openinference/anthropic/messages_test.go
ContentBlock 이벤트의 인덱스를 공통 범위 검사로 검증하고, 음수 delta 및 stop 인덱스가 panic 없이 무시되는 테스트가 추가되었다.

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

Possibly related PRs

  • inflearn/ai-gateway#4: Anthropic 스트림 변환기의 콘텐츠 블록 인덱스 방어 로직과 회귀 테스트가 직접 겹친다.
  • inflearn/ai-gateway#5: ReferenceGrant 검증과 Anthropic 스트림 인덱스 검증 변경이 직접 관련된다.

Poem

토끼가 당근처럼 이름을 꼭 맞추고
음수 인덱스는 깡충 뛰어 넘어요
안전한 스트림이 차곡차곡 쌓이고
와일드카드는 넓게, 지정 이름은 정확히
깡총! 테스트도 함께 노래해요 🐇

✨ 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 feature/hotfix-triage

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

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