feat: add prompt input sanitization layer#27
Merged
realityinspector merged 3 commits intomainfrom Mar 25, 2026
Merged
Conversation
added 3 commits
March 25, 2026 06:58
…alls
Add app/prompts/sanitize.py with sanitize_prompt_input() that:
- Escapes { and } to prevent format-string injection via user input
- Strips adversarial prompt-injection patterns (ignore instructions, role hijacks, etc.)
- Removes null bytes and ASCII control characters
- Enforces a 4000-character length cap
- Normalises Unicode to NFC
Apply sanitize_prompt_input() to all user-controlled fields before
.format() calls in character_bio.py, dialog.py, and scene.py, including
sequential dialog prompt helpers.
Add 24-test suite in tests/unit/test_prompt_sanitize.py covering both
the sanitizer function and end-to-end template rendering.
- Add POSTHOG_API_KEY and POSTHOG_HOST to config - New app/feature_flags.py: init_posthog(), is_feature_enabled() async wrapper, shutdown_posthog() — safe no-op when key not set - main.py: call init_posthog() on startup, shutdown_posthog() on shutdown - Add posthog>=3.0.0 to observability extras in pyproject.toml
This reverts commit 1cd0bc0.
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.
Strips control characters, truncates oversized inputs, rejects null bytes across character_bio, dialog, and scene prompt builders. Unit tests included.