Skip to content

security: lock down Firestore rules, restrict CORS, and harden backend endpoints - #11

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1784700360-security-fixes
Open

security: lock down Firestore rules, restrict CORS, and harden backend endpoints#11
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1784700360-security-fixes

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jul 22, 2026

Copy link
Copy Markdown

Summary

Security scan of the codebase plus fixes for the critical findings. No hardcoded secrets were found in the tree or git history (all keys are read from env vars).

Critical fixes in this PR

1. Firestore rules were world read/write (frontend/firestore.rules)
The entire database was publicly readable and writable:

match /{document=**} { allow read, write }   // anyone can read/write everything

The frontend never uses the Firestore client SDK (all data access goes through the backend Admin SDK, which bypasses rules), so this is now deny-by-default:

match /{document=**} { allow read, write: if false }

2. Backend hardening (backend/index.js)

  • CORS origin: '*' → allowlist from ALLOWED_ORIGINS (defaults to https://ddalle.xyz).
  • /submit had no input validation and fed a client-controlled submissionsContract address straight into a signer-backed ethers.Contract(...).submit(). Now validates submissionsContract (ethers.utils.isAddress), and uri/prompt (type + length caps), and returns 400 instead of 500 for bad chainId.
  • WebSocket JSON.parse(data) was unguarded → a single malformed frame crashed the whole server (DoS). Now wrapped in try/catch with prompt validation.
  • Raw error objects leaked to clients (res.send({ error: e })) → replaced with a generic message; details stay in server logs.
  • Debug code ran on every boot — removed the startup downloadImage(test.jpg) and urls_from_prompt("A dog") calls that wrote a test file and burned Replicate credits on each restart.
  • Optional auth: BACKEND_API_KEY, when set, is required via the x-api-key header (HTTP) / apiKey field (WS). Left optional for backward compatibility, with a startup warning when unset. Added express.json({ limit: '100kb' }).

3. Insecure dependency (backend/package.json)
Bumped axios ^0.27.2^1.x (0.27 is affected by SSRF/CSRF advisories). Code is compatible (only response.data.* is used).

Reported but not changed (need maintainer decision)

  • Signer pays gas for arbitrary contracts: even with address validation, /submit still lets any caller have the backend relayer wallet sign a .submit() to any address on a supported chain. Real fix is to verify submissionsContract belongs to a known DDALLE task on-chain and/or require BACKEND_API_KEY. Enabling BACKEND_API_KEY mitigates this today.
  • Remaining npm audit findings (~39, mostly transitive via ethers@5 and firebase-admin@11). Upgrading is a breaking major bump (ethers 5→6) and out of scope for a security patch — flagging for a follow-up.
  • blockchain/hardhat.config.ts reads PRIVATE_KEY from env (fine); no change needed.

Notes for deploy

If you set BACKEND_API_KEY, the frontend must send it (x-api-key / apiKey); it's currently unset so existing behavior is unchanged.

Link to Devin session: https://app.devin.ai/sessions/68d456f442b346d29df6fdb6653bfaf0
Requested by: @walnutwaldo


Devin Review

Status Commit
⚪ Not started

Run Devin Review

Open in Devin Review (Staging)

…input

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@walnutwaldo walnutwaldo self-assigned this Jul 22, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 414d7ca):

https://decentralized-dall-e--pr11-devin-1784700360-sec-5klwn8l7.web.app

(expires Wed, 29 Jul 2026 06:08:58 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 9f3ca659ce42113c1a9d85a3ba19a54f05478557

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.

1 participant