feat: implement end-to-end secure vault architecture with NoSQL, OTP-auth, and RBAC#94
feat: implement end-to-end secure vault architecture with NoSQL, OTP-auth, and RBAC#94CodeByRachit wants to merge 24 commits intoKathiraveluLab:devfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Behavioral Health Vault (BHV) by introducing a comprehensive security and privacy suite. It establishes a robust user authentication system, ensuring that each user's sensitive data is securely isolated within their private vault. The changes also streamline account management through email-based OTP for password resets and email verification, alongside integrating Google OAuth for convenient and secure sign-ins. Furthermore, the user interface has been upgraded to provide a more secure and intuitive experience, complemented by crucial infrastructure updates to safeguard sensitive configuration files. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces significant new features for user authentication, private data vaults, and security enhancements, covering email/password signup, Google OAuth, OTP-based password reset, and secure file handling. However, it introduces several critical and high-severity security vulnerabilities, including a hardcoded fallback for the SECRET_KEY that compromises session management, a complete lack of CSRF protection on sensitive POST routes, and the use of a non-cryptographically secure PRNG for OTP generation. The absence of rate limiting on the password reset endpoint further exacerbates the risk of brute-force attacks. Additionally, there are issues such as a merge conflict in .gitignore, a broken dependency in requirements.txt, duplicated JavaScript code in templates, and opportunities to make SMTP server configurations more flexible.
|
@pradeeban @mdxabu Can you please review this pr |
|
@mdxabu Hi Sir, as suggested, I have closed the earlier PRs. I will continue pushing all further commits here. Please let me know if any changes are required. Thank you! |
|
@mdxabu @pradeeban Added some new security features and UI updates to this PR! 🔐 Security Updates
🎨 UI/UX Improvements
Open to any feedback or suggestions! |
|
@mdxabu @pradeeban Sir Today I implemented 🔑 What's New:
The vault is now significantly more secure against server-side data breaches! |
|
@mdxabu @pradeeban Implemented a FastAPI-WSGI gateway with an asynchronous Motor/MongoDB layer for high-performance, non-blocking storage of unstructured narratives. |
|
@mdxabu @pradeeban Updated the core architecture to FastAPI/MongoDB with AES-256 encryption to complete the Zero-Knowledge privacy milestone; please review. |
…ents Implemented disk-spooling with explicit GC to maintain a 10MB RAM footprint during 100MB file uploads. Verified throughput at ~182MB/s.
Refactored ingestion to use a 64KB async generator. Verified 1GB throughput at ~185MB/s with 10MB RAM ceiling. Bypasses framework buffering to ensure stability on resource-constrained hardware.
Verified 500MB round-trip processing at >1GB/s with zero memory bloat and matching SHA-256 hashes.
|
@mdxabu @pradeeban Here are the benchmark results for the new end-to-end flow: Could you please re-review this PR when you have a moment? I made several core changes to support this streaming model. |
|
@mdxabu @pradeeban Implemented a memory-safe Search API with database-level pagination to efficiently filter patient vault records without overloading server RAM. |
|
Good work. Tagged "on hold" per our BHV convention. |
Thanks, @pradeeban I recall the 'on hold' convention from the recent BHV discussions. |
|
@mdxabu @pradeeban Added a secure email update flow to prevent Account Takeovers (ATO). > Users must now verify a 6-digit OTP sent to their new email address before the system officially updates their profile in the database. |
|
@mdxabu @pradeeban Hardened the AES-CTR streaming pipeline with fail-fast key validation and an 11-case cryptographic Pytest suite. |
|
@pradeeban @mdxabu Following up on the authentication discussion #111 : you mentioned preferring a minimal, zero-bloat approach like Google OAuth. Just to clarify, does this mean we should completely discard a traditional email/password registration flow? Building an email confirmation loop would require integrating an SMTP service, so relying strictly on OAuth would definitely keep the deployment much lighter. Happy to implement whichever direction you prefer! |
|
@CodeByRachit Email/Password should be ok. What we don't want is another Clerk-style auth. A local API gateway solution would be far easier to manage. |
@pradeeban Understood completely. I'll drop the external OAuth/third-party dependencies and stick to a self-contained Email/Password system using our own database and JWTs for the local API gateway. Does that align exactly with what you're looking for? |
|
We leave that up to you. :) Remember, we are evaluating the project proposal for an empty repository. Please also refer to Acceptable-and-Ethical-AI-Use-Policy.md when drafting your GSoC proposal or GitHub conversations on the use of AI. We keep receiving AI-drafted proposals that we are ranking much lower than human-drafted proposals. |
|
@pradeeban Thanks for that information; I will use the local JWT and email/password method since I think that one makes the most sense for air-gapped clinics as well. I completely understand the AI policy and will write my final proposal with 100% original wording and an architecturally view. Thank you for your help. |
|
@pradeeban @mdxabu I have submitted my idea proposal and kept only one single pr(this one ) so that it is easy for you to consolidating to see the prototype (recommended by @mdxabu ) Thank you so much for your guidance |
|
Hi @pradeeban @mdxabu , is it okay if I continue making small updates to refine the prototype while we wait for the results? |
|
@CodeByRachit, of course. Open source projects always appreciate volunteer contributions (although BHV is in an awkward spot. We had a similar situation in the Beehive in the past when it was an empty repository. But that time, the volume was more manageable. Now with BHV, there are several PRs on-hold. Going to be tricky). |
|
sure @pradeeban Since this is already quite large PR , what is the best way forward to avoid adding to the review bottleneck? Should I keep updating it, or start a new, smaller PR? |
|
@CodeByRachit You can keep updating this PR. |
|
Understood @pradeeban |
|
@pradeeban @mdxabu Implemented and passed a 39-case security test suite validating our core crypto engine, auth flows, and RBAC logic. |
1c9b2f1 to
94befc5
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a security-focused “Behavioral Health Vault” prototype that combines Flask (auth/RBAC/UI) with FastAPI (streaming ingestion/download) and MongoDB (vault storage), plus a refreshed UI for upload/gallery/admin dashboards.
Changes:
- Added Flask auth system features (email verification, OTP reset, TOTP 2FA) and RBAC dashboards (admin/owner), plus secure upload/gallery routes.
- Implemented crypto utilities for Fernet at-rest encryption and AES-CTR streaming encryption/decryption with integrity hashing.
- Added extensive UI templates and basic pytest suites for auth and crypto behaviors, plus dependency and ignore-file updates.
Reviewed changes
Copilot reviewed 19 out of 22 changed files in this pull request and generated 26 comments.
Show a summary per file
| File | Description |
|---|---|
app.py |
Core Flask + FastAPI hybrid app: auth, RBAC, OTP/TOTP flows, ingestion/gallery/vault endpoints, and security headers |
models.py |
SQLAlchemy user/entry models + Motor-based MongoDB persistence and GridFS streaming helpers |
crypto.py |
Fernet + AES-CTR streaming crypto helpers and chunked ingestion helper |
validators.py |
File upload validation and filename anonymization |
requirements.txt |
Pinned Python dependencies for Flask/FastAPI/Mongo/crypto stack |
test_auth.py |
Flask auth integration/security-oriented tests |
test_crypto.py |
Crypto integrity and security regression tests |
templates/base.html |
Base layout, navigation, theme toggle, and delete modal logic |
templates/welcome.html |
Landing page UI |
templates/login.html |
Login/signup/forgot-password UI with client-side validation and OTP request |
templates/login_2fa.html |
TOTP prompt UI |
templates/profile.html |
Profile dashboard, avatar upload, password change, and email-update OTP flow |
templates/setup_2fa.html |
2FA enrollment UI (QR + secret) |
templates/upload.html |
Upload UI with file preview and narrative entry |
templates/gallery.html |
Gallery UI with download/delete controls |
templates/admin_dashboard.html |
Admin metrics + patient directory UI |
templates/admin_view_vault.html |
Admin read-only view into a patient’s records |
templates/owner_dashboard.html |
Owner system dashboard UI |
static/img/js/upload.js |
Duplicated upload preview JS logic extracted to static file |
static/img/js/main.js |
Duplicated base template JS logic extracted to static file |
.gitignore |
Added local env/venv/cache/db ignores |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@pradeeban @mdxabu Sorry about the Copilot auto-review noise—an unexpected setting triggered it. I've implemented rate limiting for brute-force protection and hardened the authentication test suite with 20+ passing cases |
|
@mdxabu @pradeeban Can you please review this pr again with all the changes made |
|
@mdxabu @pradeeban Strict backend rate-limiting to block brute-force attacks |
Behavioral Health Vault (BHV) - Core Security & Ingestion Engine
Overview
This Pull Request implements the high-performance, security-first architecture for the Behavioral Health Vault (BHV) as outlined in my GSoC '26 proposal. I have successfully migrated the legacy stack to a modern FastAPI/Flask + MongoDB hybrid engine, focusing on "Privacy by Default," Zero-Knowledge principles, and memory-efficient data handling.
Security & Privacy Suite (Zone 1 & 2)
Performance & Engineering
UI/UX & Adaptive Design
Technical Stack & Dependencies
Changelog Summary
serve_fileroute for secure in-memory decryption loop..gitignoreand.env.examplefor secure deployment.Note for Mentors: As suggested by @mdxabu, I have consolidated my work into this single PR to provide a unified view of the BHV prototype development for GSoC evaluation.