security: lock down Firestore rules, restrict CORS, and harden backend endpoints - #11
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
security: lock down Firestore rules, restrict CORS, and harden backend endpoints#11devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…input Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
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 |
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.
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:
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:
2. Backend hardening (
backend/index.js)origin: '*'→ allowlist fromALLOWED_ORIGINS(defaults tohttps://ddalle.xyz)./submithad no input validation and fed a client-controlledsubmissionsContractaddress straight into a signer-backedethers.Contract(...).submit(). Now validatessubmissionsContract(ethers.utils.isAddress), anduri/prompt(type + length caps), and returns400instead of500for badchainId.JSON.parse(data)was unguarded → a single malformed frame crashed the whole server (DoS). Now wrapped in try/catch with prompt validation.res.send({ error: e })) → replaced with a generic message; details stay in server logs.downloadImage(test.jpg)andurls_from_prompt("A dog")calls that wrote a test file and burned Replicate credits on each restart.BACKEND_API_KEY, when set, is required via thex-api-keyheader (HTTP) /apiKeyfield (WS). Left optional for backward compatibility, with a startup warning when unset. Addedexpress.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 (onlyresponse.data.*is used).Reported but not changed (need maintainer decision)
/submitstill lets any caller have the backend relayer wallet sign a.submit()to any address on a supported chain. Real fix is to verifysubmissionsContractbelongs to a known DDALLE task on-chain and/or requireBACKEND_API_KEY. EnablingBACKEND_API_KEYmitigates this today.npm auditfindings (~39, mostly transitive viaethers@5andfirebase-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.tsreadsPRIVATE_KEYfrom 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