refactor: harden D1 database operations and optimize memory management (#263)#265
Open
ojaswa072 wants to merge 2 commits intoOWASP-BLT:mainfrom
Open
refactor: harden D1 database operations and optimize memory management (#263)#265ojaswa072 wants to merge 2 commits intoOWASP-BLT:mainfrom
ojaswa072 wants to merge 2 commits intoOWASP-BLT:mainfrom
Conversation
🍃 PR Readiness CheckCheck the readiness of this PR on Leaf: Leaf reviews pull requests for operational readiness, security risks, and production-impacting changes before they ship. |
4b808c4 to
c332edc
Compare
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
Resolves #263. This PR implements a comprehensive hardening of the database layer. While the initial audit was focused on SQL injection, the refactor addresses deeper architectural risks related to the Pyodide/D1 bridge and Worker environment stability.
Key Changes
.first(),.all(), and.run()) now consistently call.to_py()followed by.destroy(). This ensures that JavaScript proxy objects are explicitly garbage-collected, preventing memory bloat in the Worker isolate..prepare().bind().run()inline chaining pattern. This ensures the statement context is preserved across the bridge boundary and improves code readability.upsert_prand other write operations now capture and handle the.run()result, ensuring that silent D1 failures (like constraint violations) can be properly tracked.dir(env)debug log fromget_db. This prevents the potential exposure of sensitive binding names and secret keys in production logs.Verification Results
wrangler devJsProxydestruction logic via memory usage monitoring?) exclusively