Repository navigation
fix(go-models): harden 302.AI driver requests - #15289
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR centralizes input validation/trim logic and Authorization header handling across AI302Model methods, adjusts ListModels to use a GET with typed response parsing, ensures ShowTask URL-escapes task IDs, removes internal SSE-line logging, and adds comprehensive tests for request/response flows and input validation. ChangesAI302 Provider Hardening
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
internal/entity/models/302ai.go (2)
926-946:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDon't splice raw
taskIDinto the request path.
strings.TrimSpacestill allows/,?, and#, so a crafted task ID can change the request path or query instead of addressing a single task resource. Escape the path segment or reject task IDs containing reserved URL characters before buildingapiURL.🤖 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 `@internal/entity/models/302ai.go` around lines 926 - 946, The code currently interpolates taskID directly into apiURL allowing reserved characters to alter the path; sanitize or escape the task id before constructing the URL. Replace usage of strings.TrimSpace(taskID) when building apiURL with a trimmed-and-URL-escaped segment (use url.PathEscape on the trimmed taskID) or alternatively validate/reject taskIDs containing '/', '?', '#' etc., then build apiURL from a.BaseURL[region], a.URLSuffix.DocumentParse and the escaped task id so http.NewRequest always targets the intended resource.
697-718:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winValidate caller-supplied document URLs before forwarding them.
These paths only trim
urls/documentURL, so malformed values still reach 302.ai even thoughParseFilenow says it requires a valid public document URL. Reject obviously invalid URL strings here so callers fail locally instead of after a network round-trip.Also applies to: 789-809
🤖 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 `@internal/entity/models/302ai.go` around lines 697 - 718, The code currently forwards caller-supplied urls/documentURL without validating them; update the handler around the urls/documentURL usage (the variables named urls and documentURL in the 302ai.go flow that also calls ParseFile) to parse and validate each trimmed URL before proceeding: use net/url (url.Parse or url.ParseRequestURI) and ensure scheme is http or https and that Host is non-empty, returning an error (e.g., "invalid document URL") if validation fails; apply the same change to both occurrences referenced (the block using urls near where modelName/ apiConfig are validated and the later block at ~789-809) so malformed URLs are rejected locally instead of being sent to 302.ai.
🤖 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 `@internal/entity/models/302ai.go`:
- Around line 926-946: The code currently interpolates taskID directly into
apiURL allowing reserved characters to alter the path; sanitize or escape the
task id before constructing the URL. Replace usage of strings.TrimSpace(taskID)
when building apiURL with a trimmed-and-URL-escaped segment (use url.PathEscape
on the trimmed taskID) or alternatively validate/reject taskIDs containing '/',
'?', '#' etc., then build apiURL from a.BaseURL[region],
a.URLSuffix.DocumentParse and the escaped task id so http.NewRequest always
targets the intended resource.
- Around line 697-718: The code currently forwards caller-supplied
urls/documentURL without validating them; update the handler around the
urls/documentURL usage (the variables named urls and documentURL in the 302ai.go
flow that also calls ParseFile) to parse and validate each trimmed URL before
proceeding: use net/url (url.Parse or url.ParseRequestURI) and ensure scheme is
http or https and that Host is non-empty, returning an error (e.g., "invalid
document URL") if validation fails; apply the same change to both occurrences
referenced (the block using urls near where modelName/ apiConfig are validated
and the later block at ~789-809) so malformed URLs are rejected locally instead
of being sent to 302.ai.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d5e5bb15-79f6-45c2-9d44-809651cedb0e
📒 Files selected for processing (2)
internal/entity/models/302ai.gointernal/entity/models/302ai_test.go
|
hi @Haruko386 - another driver improvement - sorry for throwing so many at you, I have many on my list to fix! |
383f395 to
3ec12c6
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15289 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
What changed
streamvalues in request payloads.ListModelsas a bodyless GET and parse the response with typed JSON structs instead of unchecked assertions.Why
The driver could panic or send inconsistent requests when optional config fields were nil, empty, malformed, or contradicted the method path. This keeps provider-driver behavior explicit while preserving the existing supported 302.AI flows.
Validation
go test ./internal/entity/models -run TestAI302 -count=1go test ./internal/entity/models -run 'TestAI302|TestJieKouAI' -count=1go test -race ./internal/entity/models -run TestAI302 -count=1git diff --checkNotes
go test ./internal/entity/models -count=1is currently blocked by an unrelated upstream panic inTestAstraflowEmbedReturnsNoSuchMethod.Closes #14736