fix: add validation for search query parameters#113
Open
virakshi07 wants to merge 1 commit into
Open
Conversation
Contributor
|
Hi @virakshi07, thanks for your contribution! ⭐ This repository requires contributors to star the repository before a Please star the repo: https://github.com/PandyaJeet/SuperBrowser Once you've starred it, push any commit (or reopen the PR) to re-run this |
Comment on lines
+58
to
+68
| async def get_ai( | ||
| q: str = Query( | ||
| ..., | ||
| min_length=1, | ||
| max_length=500 | ||
| ), | ||
| session_id: str = "", | ||
| persona: str = "default", | ||
| gl: str = "us", | ||
| model: str = "llama-3.1-8b-instant" | ||
| ): |
Contributor
There was a problem hiding this comment.
you added validation for q but the function signature still defaults persona and gl to plain strings. since you changed the request model (ContextualAIRequest) to validate persona choices via Literal and restricted region max length, consider applying the same Query validation rules to persona and gl in this legacy path to keep the API behaviors aligned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds input validation to search endpoints and AI request models to prevent empty or excessively long queries from reaching upstream APIs and scrapers.
Changes Made
SEO Endpoint
Added FastAPI
Queryvalidation:min_length=1max_length=500Removed manual 400 validation logic
Community Endpoint
Added FastAPI
Queryvalidation:min_length=1max_length=500Removed manual 400 validation logic
AI Contextual Request Model
Added Pydantic
Fieldvalidation forquerymin_length=1max_length=500Added
Literalvalidation for supported persona values:defaultchatgptgeminiperplexityclaudeAdded validation for
regionfield (max_length=4)Legacy AI Endpoint
Added query validation using FastAPI
Querymin_length=1max_length=500Validation Results
Closes #20
Apologies for the late submission. The fix has been implemented, thoroughly tested, and all acceptance criteria have been verified. Thank you for your understanding.