Skip to content

fix: add validation for search query parameters#113

Open
virakshi07 wants to merge 1 commit into
PandyaJeet:mainfrom
virakshi07:fix-search-query-validation-20
Open

fix: add validation for search query parameters#113
virakshi07 wants to merge 1 commit into
PandyaJeet:mainfrom
virakshi07:fix-search-query-validation-20

Conversation

@virakshi07

@virakshi07 virakshi07 commented Jun 22, 2026

Copy link
Copy Markdown

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 Query validation:

    • min_length=1
    • max_length=500
  • Removed manual 400 validation logic

Community Endpoint

  • Added FastAPI Query validation:

    • min_length=1
    • max_length=500
  • Removed manual 400 validation logic

AI Contextual Request Model

  • Added Pydantic Field validation for query

    • min_length=1
    • max_length=500
  • Added Literal validation for supported persona values:

    • default
    • chatgpt
    • gemini
    • perplexity
    • claude
  • Added validation for region field (max_length=4)

Legacy AI Endpoint

  • Added query validation using FastAPI Query

    • min_length=1
    • max_length=500

Validation Results

  • Empty queries now return HTTP 422
  • Queries longer than 500 characters return HTTP 422
  • Invalid persona values return HTTP 422
  • Existing valid queries continue to work correctly

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.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @virakshi07, thanks for your contribution! ⭐

This repository requires contributors to star the repository before a
pull request can be merged.

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
check and it will turn green. Thank you! 🎉

@github-actions github-actions Bot added the gssoc:approved GSSoC approved PR - earns base 50 pts label Jun 22, 2026
Comment thread backend/routers/ai.py
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"
):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC approved PR - earns base 50 pts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: No input validation on search query params - allows abuse

2 participants