Skip to content

Security hardening: prompt guardrails, input validation, CORS, error handling#10

Open
BrandonS7 wants to merge 1 commit intoBirmingham-AI:mainfrom
BrandonS7:security/hardening
Open

Security hardening: prompt guardrails, input validation, CORS, error handling#10
BrandonS7 wants to merge 1 commit intoBirmingham-AI:mainfrom
BrandonS7:security/hardening

Conversation

@BrandonS7
Copy link
Copy Markdown

What this does

Addresses several security gaps found during code review:

1. Prompt injection guardrails

Added a Boundaries section to both carrie.txt and carrie_voice.txt system prompts. This tells the model to:

  • Stay in the Carrie/Birmingham AI assistant role
  • Decline requests to ignore instructions or role-play as someone else
  • Not reveal system prompt contents
  • Redirect off-topic or inappropriate questions

2. Input validation

  • Added max_length=4000 to question field (prevents prompt stuffing / cost attacks)
  • Added max_length=50 to conversation history (prevents unbounded context injection)

3. CORS configuration

Replaced hardcoded allow_origins=["*"] with configurable ALLOWED_ORIGINS env var. Defaults to * for backward compatibility, but can now be locked down per environment.

4. Error message sanitization

All except blocks now log full error details server-side via logger.error() but return generic "Internal server error" to clients. Previously, str(e) was returned directly, which could leak internal paths, stack traces, or API provider details.

5. Conversation history context boundary

Added explicit boundary marker in streaming_agent.py so the model treats injected conversation history as user-provided content rather than system instructions. Mitigates a class of indirect prompt injection where crafted history messages could override system behavior.


All changes are minimal and surgical. No new dependencies, no refactoring, no behavior changes beyond the security improvements.

@ldanielkeysys ldanielkeysys self-requested a review February 19, 2026 20:49
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.

2 participants