Skip to content

Remove hardcoded API key, fix XSS in chat rendering - #2

Draft
killerpanda101 wants to merge 3 commits into
mainfrom
claude/fix-xss-and-hardcoded-key
Draft

killerpanda101 wants to merge 3 commits into
mainfrom
claude/fix-xss-and-hardcoded-key

Conversation

@killerpanda101

Copy link
Copy Markdown
Owner

Summary

  • Hardcoded API key removed: app.py set OPENAI_API_KEY to a literal string (and the README told users to do the same). It now reads it from the environment / .env (load_dotenv() was imported but never called) and shows a clear error if missing. .env is git-ignored.
  • XSS fix: chat messages (LLM output derived from uploaded PDFs, and user input) were interpolated into HTML rendered with unsafe_allow_html=True. They are now html.escaped.
  • Bug fix: PdfReader.extract_text() can return None (e.g. image-only pages), which crashed with a TypeError.

Action needed

The old key string remains in git history. If it was ever a real key, revoke/rotate it in the OpenAI dashboard.

Not run end-to-end (needs an OpenAI key); py_compile passes.


Generated by Claude Code

- Load OPENAI_API_KEY from env/.env instead of hardcoding it in app.py
- html.escape chat messages before rendering with unsafe_allow_html (XSS via PDF/LLM content)
- Handle PDF pages with no extractable text (extract_text() may return None)
- Ignore .env and update README

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGgdMjDH3WUa81iXsg3kwF
- .gitignore for secrets, OS/editor files and language build artifacts
- Untrack files that are now ignored (kept on disk)
- pre-commit config (gitleaks, private keys, large files) and CI secret scan

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGgdMjDH3WUa81iXsg3kwF

Copy link
Copy Markdown
Owner Author

Also added repo safeguards in a follow-up commit: a language-appropriate .gitignore (secrets, OS/editor files, build artifacts), .pre-commit-config.yaml (gitleaks, private-key and large-file checks; enable with pip install pre-commit && pre-commit install) and a CI workflow that runs a secret scan and fails if node_modules/caches are committed.


Generated by Claude Code

Full-history scans fail on secrets that were committed before this PR;
those must be rotated, not re-flagged on every run.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGgdMjDH3WUa81iXsg3kwF
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