Skip to content

security: decouple settings keys and sandbox game iframes#369

Open
afnan0304 wants to merge 1 commit into
kaifansariw:mainfrom
afnan0304:fix-secret-key-and-iframe-sandbox
Open

security: decouple settings keys and sandbox game iframes#369
afnan0304 wants to merge 1 commit into
kaifansariw:mainfrom
afnan0304:fix-secret-key-and-iframe-sandbox

Conversation

@afnan0304
Copy link
Copy Markdown

@afnan0304 afnan0304 commented May 16, 2026

📝 Pull Request Template

📄 Description

This PR fixes two major security flaws where the app was leaving its keys out in the open and letting third-party game code touch sensitive user data.

  • Backend: Cleaned up settings.py. Instead of hardcoding the master SECRET_KEY, leaving DEBUG=True, and allowing all hosts (*), the app now uses python-dotenv to safely load these settings from a local .env file. I also added a bulletproof parser for ALLOWED_HOSTS that handles extra spaces or commas gracefully and defaults to local setup if empty.

  • Frontend: Locked down the game components (GamePlayPage.jsx and GameModal.jsx). I added sandbox="allow-scripts allow-forms" to the game iframes. Leaving out the allow-same-origin flag forces the browser to isolate the game completely. Even though the games run on the same domain, they are now legally blocked by the browser from sneaking into localStorage and stealing user auth tokens.

  • Environment Files: Created a new frontend/.env.example file to serve as a blueprint for the frontend setup, ensuring other developers know exactly how to configure their local environment keys without leaking real ones.

🔗 Related Issues

Fixes #368


🧩 Type of Change

Select the type of change your PR introduces (check all that apply):

  • 🐛 Bug Fix

  • ✨ New Feature

  • ⚡ Enhancement / Optimization

  • 🧰 Refactoring

  • 🧾 Documentation Update

  • 🔧 Other (please specify): Security Patch


✅ Checklist

Before submitting your PR, please confirm the following:

  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added or updated relevant documentation.
  • My changes do not break any existing functionality.
  • I have tested my changes locally and they work as expected.
  • I have linked all relevant issues (if any).

💬 Additional Notes (Optional)

This completely solves the token leak and hardcoded secret bugs for GSSoC'26. Everything runs perfectly fine on local env files.

Signed-off-by: afnan0304 <mhdafnan309@gmail.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

@afnan0304 is attempting to deploy a commit to the kaif ansari 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 16, 2026

Deploy Preview for gamehub-99999 failed.

Name Link
🔨 Latest commit e2d66a2
🔍 Latest deploy log https://app.netlify.com/projects/gamehub-99999/deploys/6a07d104e707a500098106a6

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.

[SECURITY] Hardcoded SECRET_KEY and Unsandboxed Same-Origin Game Iframes

1 participant