Skip to content

Latest commit

Β 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“„ DocuShare β€” Secure Document Sharing

One-time download codes. Zero leaks.
Upload a document URL β†’ Get 5 unique codes β†’ Share securely.

Python Flask Supabase bcrypt MIT License Security Status


✨ Features

Icon Feature What it does
πŸ“€ Upload & Share Submit a document URL, get 5 unique one-time download codes
πŸ” Secure by Design Each code expires after 7 days or first use β€” never reused
πŸ“Š Dashboard Manage documents, generate new codes, track usage, delete
πŸ”‘ Recovery 10-character recovery codes if you forget your user ID
πŸ›‘οΈ Session Auth Log in once, no repeated password prompts
🧱 CSRF Protection All forms protected against cross-site request forgery
⏱️ Rate Limiting Prevents brute-force attacks on auth and code endpoints
πŸ”’ Account Lockout 5 failed attempts β†’ temporary block
βœ… URL Validation Blocks javascript:, localhost, private IPs

🧰 Tech Stack

πŸ—οΈ Layer πŸ› οΈ Technology
Framework Flask
Database Supabase (PostgreSQL)
Auth bcrypt + Flask sessions
Security Talisman Β· WTF Β· Limiter
Deployment Gunicorn

πŸ“ Project Structure

πŸ“¦ document_sharing_app/
β”œβ”€β”€ 🐍 app.py                  # Main Flask application
β”œβ”€β”€ πŸ—„οΈ schema.sql              # Supabase/PostgreSQL schema + migrations
β”œβ”€β”€ πŸ“‹ requirements.txt        # Python dependencies
β”œβ”€β”€ πŸ”’ .env                    # Environment variables (credentials)
β”œβ”€β”€ πŸ“– README.md               # This file
β”œβ”€β”€ πŸ“„ LICENSE                 # MIT License
β”œβ”€β”€ πŸ“ document_sharing_app_security_audit.md  # Full security audit
β”œβ”€β”€ 🎨 static/
β”‚   β”œβ”€β”€ 🎭 style.css           # Application styles
β”‚   └── ⚑ script.js           # Client-side JavaScript
└── πŸ“‚ templates/
    β”œβ”€β”€ 🏠 base.html           # Layout template (nav, fonts, icons)
    β”œβ”€β”€ πŸ“€ index.html          # Upload page + registration receipt
    β”œβ”€β”€ πŸ”‘ existing.html       # Login form + user dashboard
    β”œβ”€β”€ πŸ” forget.html         # Recover user ID + recovery codes
    └── ⬇️ download.html       # Code redemption page

πŸ”„ How It Works

πŸ‘€ For Document Owners

1️⃣  Register      β†’  Go to /, enter document URL, name & password
2️⃣  Get Codes     β†’  App generates 5 unique one-time download codes
3️⃣  Share         β†’  Send any code to your intended recipient
4️⃣  Manage        β†’  Log in at /existing to view docs, generate codes, delete
5️⃣  Recover       β†’  Used /forget to retrieve your user ID

πŸ“₯ For Recipients

1️⃣  Go to /download
2️⃣  Enter the code you received
3️⃣  βœ… Valid β†’ Document URL is revealed
4️⃣  ❌ Code marked used β€” cannot be reused

πŸš€ Setup Guide

πŸ“‹ Prerequisites

πŸ“¦ 1. Clone & Install

git clone https://github.com/ocean-master0/document_sharing_app.git
cd document_sharing_app
pip install -r requirements.txt

☁️ 2. Create a Supabase Project

βš™οΈ Setting πŸ” Where to find it
SUPABASE_URL Project Settings β†’ API β†’ Project URL
SUPABASE_ANON_KEY Project Settings β†’ API β†’ anon public key

πŸ” 3. Configure Environment

Create a .env file in the project root:

SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=use your-anon-public-key-here
SECRET_KEY=your-64-character-hex-secret-key

# Optional:
# ENVIRONMENT=production
# REDIS_URL=redis://your-redis-host:6379

πŸ’‘ Generate a secure key: python -c "import secrets; print(secrets.token_hex(32))"

πŸ—„οΈ 4. Initialize the Database

Step Action
1 Open Supabase Dashboard β†’ SQL Editor
2 Copy contents of schema.sql
3 Paste & click Run

Creates all tables, indexes, and permissions. βœ…

▢️ 5. Run the Application

python app.py

Opens at http://0.0.0.0:5000 πŸš€

🌐 6. Production Deployment

gunicorn \
  --workers 4 \
  --worker-class gthread \
  --threads 2 \
  --bind 0.0.0.0:$PORT \
  --timeout 30 \
  --max-requests 1000 \
  app:app

Set ENVIRONMENT=production to enable:

  • HTTPS
  • HSTS
  • Cookies

πŸ”Œ API Endpoints

πŸ›£οΈ Method πŸ›€οΈ Route πŸ“ Description πŸ”‘ Auth
GET/POST / Register + upload document ❌
GET/POST /existing Login / Dashboard βœ…
POST /login Login endpoint ❌
GET /logout Logout βœ…
GET/POST /forget Recover user ID ❌
GET/POST /download Redeem download code ❌*
POST /download_codes Download codes as .txt βœ…
POST /download_forget_codes Download recovery codes as .txt βœ…
GET /.well-known/security.txt Security disclosure ❌

*CSRF exempt β€” codes are single-use by nature.


πŸ›‘οΈ Security Features

πŸ† Feature βš™οΈ Implementation 🎯 Status
Password storage bcrypt with salt (12 rounds) 🟒
Download codes SHA-256 hashed before DB storage 🟒
Recovery codes SHA-256 hashed before DB storage 🟒
Sessions Signed cookies with 8-hour expiry 🟒
CSRF Flask-WTF CSRFProtect on all POST requests 🟒
Rate limiting Per-IP, 10 req/min auth, 20 req/min download 🟒
Account lockout 5 failed attempts β†’ temporary block 🟒
URL validation Only http/https, blocks private/internal IPs 🟒
Security headers CSP, HSTS, XSS Protection, Referrer Policy 🟒
Timing attacks Constant-time compare + dummy bcrypt 🟒
Log injection CRLF sanitized in log messages 🟒
πŸ“‹ Click to view the full security audit

A comprehensive security audit identified 19 vulnerabilities (2 critical, 6 high, 5 medium, 4 low, 2 info) β€” all have been fixed.

See document_sharing_app_security_audit.md for the complete report.


πŸ—„οΈ Database Schema

πŸ‘€ users

πŸ“Œ Column 🏷️ Type πŸ“ Description
user_id_hash TEXT (PK) SHA-256 of user ID
password_hash TEXT bcrypt hashed password
created_at TIMESTAMPTZ Registration timestamp

πŸ“„ documents

πŸ“Œ Column 🏷️ Type πŸ“ Description
id BIGSERIAL (PK) Auto-incrementing ID
url TEXT Document URL
doc_name TEXT Document name
user_name TEXT Owner's display name
user_id_hash TEXT (FK) Owner's user ID hash
user_id TEXT Owner's user ID (display)
code TEXT (UNIQUE) SHA-256 hashed download code
used BOOLEAN Whether code has been used
created_at TIMESTAMPTZ Creation timestamp

πŸ”‘ forget_codes

πŸ“Œ Column 🏷️ Type πŸ“ Description
id BIGSERIAL (PK) Auto-incrementing ID
user_id_hash TEXT (FK) Owner's user ID hash
user_id TEXT Owner's user ID
code TEXT (UNIQUE) SHA-256 hashed recovery code
used BOOLEAN Whether code has been used
created_at TIMESTAMPTZ Creation timestamp

πŸ“œ License

MIT β€” Copyright Β© 2026 ocean-master0

See LICENSE for full text.

Open Source

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages