Kosh is a modern Flask application for secure file sharing over a local network using AES encryption and simulated Attribute-Based Encryption (ABE). It features a beautiful Tailwind-based UI, an admin dashboard for user and policy management, real-time synchronization, and improved file structure for scalability.
pip install -r requirements.txt
python3 -m app.app
Open your browser: http://localhost:7130
Default Login:
adminpassThe application is now running. You can:
Note: All files stored in data/ and app/uploads/. Simple JSON-based storage (no database needed). Real-time updates using WebSockets. AES encryption for all files.
Kosh uses minimal, well-maintained dependencies:
All dependencies are specified in requirements.txt and can be installed with:
pip install -r requirements.txt
Kosh uses a centralized configuration system (app/config.py) with environment variable support.
Create a .env file from the template:
cp .env.example .env
Available configuration options:
| Variable | Default | Description |
|---|---|---|
KOSH_SECRET_KEY |
kosh-secret-key-change-in-production |
Flask secret key for sessions |
KOSH_DEBUG |
True |
Enable debug mode |
KOSH_HOST |
0.0.0.0 |
Host to bind to (0.0.0.0 = all interfaces) |
KOSH_PORT |
7130 |
Port to run on |
KOSH_AUDIT_RETENTION_DAYS |
60 |
Days to keep audit logs |
Configured in app/config.py:
MAX_FILE_SIZE = 5 * 1024 * 1024 * 1024 # 5GB
ALLOWED_EXTENSIONS = {
'txt', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'csv',
'jpg', 'jpeg', 'png', 'gif', 'zip', 'rar', 'py', 'js', 'json',
'mp4', 'mov', 'avi', 'mkv'
}
IV_SIZE = 16 # AES block size (bytes)
CHUNK_SIZE = 65536 # 64KB chunks for stream processing
TAG_SIZE = 32 # HMAC-SHA256 output size (bytes)
Automatically created on first run:
data/ - Data files (users, policies, attributes, audit logs, keys)app/uploads/ - Encrypted file storagekosh/
βββ app/
β βββ __init__.py # Package initialization
β βββ app.py # Main Flask application with routes and WebSocket handlers
β βββ attribute_management.py # Attribute CRUD operations and role-based management
β βββ config.py # Centralized configuration and environment settings
β βββ utils.py # Shared utility functions for the application
β βββ crypto/
β β βββ __init__.py
β β βββ aes.py # AES-256 encryption/decryption with HMAC
β β βββ abe_simulator.py # JSON-based ABE access control simulation
β βββ static/
β β βββ admin/ # Admin dashboard specific assets
β β β βββ admin.css
β β β βββ admin-dashboard.js
β β β βββ tailwind.config.js
β β βββ dashboard/ # User dashboard specific assets
β β β βββ dashboard.css
β β β βββ dashboard.js
β β β βββ dashboard-tailwind.config.js
β β βββ shared/ # Shared components and utilities
β β β βββ components/ # Reusable UI components
β β β β βββ modal.js
β β β β βββ notification-manager.js
β β β β βββ toast.js
β β β βββ modules/ # Feature-specific modules
β β β β βββ attribute-manager.js
β β β β βββ audit-manager.js
β β β β βββ dashboard-file-manager.js
β β β β βββ file-manager.js
β β β β βββ password-manager.js
β β β β βββ policy-manager.js
β β β β βββ realtime-manager.js
β β β β βββ role-manager.js
β β β β βββ role-manager-attribute.js
β β β β βββ upload-manager.js
β β β β βββ user-manager.js
β β β βββ utils/ # UI helper utilities
β β β βββ admin-links.js
β β β βββ ui-helpers.js
β β βββ common/ # Common assets (favicons, icons, PWA manifest)
β β βββ android-chrome-192x192.png
β β βββ android-chrome-512x512.png
β β βββ apple-touch-icon.png
β β βββ favicon-16x16.png
β β βββ favicon-32x32.png
β β βββ favicon.ico
β β βββ site.webmanifest
β βββ templates/
β β βββ index.html # Login page
β β βββ dashboard.html # User dashboard
β β βββ admin.html # Admin dashboard
β βββ uploads/ # Encrypted file storage (auto-created)
βββ data/
β βββ aes_encryption.key # AES encryption key (auto-generated)
β βββ aes_hmac.key # HMAC key for integrity (auto-generated)
β βββ attributes.json # Global attribute pool
β βββ audit_logs.jsonl # System audit logs (JSONL format)
β βββ policies.json # File access policies
β βββ users.json # User accounts and attributes
βββ .github/ # GitHub templates and workflows
β βββ ISSUE_TEMPLATE/
β βββ bug_report.md
β βββ feature_request.md
βββ .env.example # Environment configuration template
βββ .gitignore # Git ignore patterns
βββ requirements.txt # Python dependencies
βββ LICENSE # License information
βββ README.md # This file
git clone https://github.com/neelshha/kosh.git
cd kosh
python -m venv venv
source venv/bin/activate # On macOS/Linux
# or
venv\Scripts\activate # On Windows
pip install -r requirements.txt
The application works with default settings, but you can customize it:
cp .env.example .env
# Edit .env file to customize settings
Available environment variables:
KOSH_SECRET_KEY: Flask secret key (change in production)KOSH_DEBUG: Enable debug mode (default: True)KOSH_HOST: Host to bind to (default: 0.0.0.0)KOSH_PORT: Port to run on (default: 7130)KOSH_AUDIT_RETENTION_DAYS: Days to keep audit logs (default: 60)python -m app.app
The application will:
data/, app/uploads/)http://localhost:7130You can access it from any device on the same local network.
admin / passpass for all usershttp://localhost:7130/admin after logging in as adminKosh includes comprehensive real-time synchronization using WebSocket technology (Socket.IO):
user_added, user_updated, user_deletedpolicy_added, policy_updated, policy_deletedattribute_added, attribute_removedaudit_log_added for system activity trackingOpen multiple browser tabs as admin to see live synchronization:
# Admin room management
@socketio.on('join_admin')
def handle_join_admin():
user_id = session.get('user_id')
if user_id == 'admin':
join_room('admin_updates')
emit('joined_admin', {'message': 'Joined admin updates'})
# Real-time event emission
socketio.emit('user_added', {
'user': user_id,
'attributes': attributes,
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
}, room='admin_updates')
// Initialize connection
const socket = io();
socket.emit('join_admin');
// Listen for real-time events
socket.on('user_added', function(data) {
addUserToTable(data.user, data.attributes);
showToast(`User "${data.user}" added`, 'success');
});
For production environments, configure specific CORS origins:
socketio = SocketIO(app, cors_allowed_origins=["https://yourdomain.com"])
Real-time features work in all modern browsers supporting WebSocket:
AES-256-CTR with HMAC-SHA256
All files are encrypted using industry-standard AES-256 in CTR mode with HMAC authentication:
Encryption Format:
[16-byte IV][Encrypted File Data][32-byte HMAC Tag]
Key Files:
data/aes_encryption.key - AES encryption key (auto-generated)data/aes_hmac.key - HMAC authentication key (auto-generated)Attribute-Based Access Control (ABE Simulation)
Role-Based Permissions
pass for all users (change in production)All users have a consistent password structure:
pass for all usersThe system automatically converts legacy user formats to the new dictionary format:
{
"username": {
"attributes": ["attr1", "attr2"],
"password": "hashed_password"
}
}
For Production Deployment:
KOSH_SECRET_KEY environment variableKOSH_DEBUG=Falsedata/ directorydata/ directory regularlyPlease report security vulnerabilities by creating an issue with the βsecurityβ label.
Supported Versions:
| Version | Supported |
|---|---|
| 5.1.x | β |
| 5.0.x | β |
| 4.0.x | β |
| < 4.0 | β |
Include in your report:
Kosh follows a modular architecture with clear separation of concerns:
Core Application (app.py)
Configuration Module (config.py)
Centralizes all application settings:
Utility Module (utils.py)
Shared helper functions:
safe_load_json(): Safe JSON file loading with error handlingparse_and_validate_attrs(): Attribute input normalization and validationlog_audit(): Comprehensive audit logging with WebSocket emissionhas_role(): Role-based permission checkinginitialize_data_files(): Bootstrap default data filesvalidate_file_upload(): File upload validationget_user_files(): User-accessible file listing with ABE filteringnormalize_user_data(): Legacy/current user format normalizationemit_socketio_event(): Centralized WebSocket event emissiondelete_file_and_policy(): File deletion with policy cleanupAttribute Management Module (attribute_management.py)
Dedicated blueprint for attribute operations:
/admin/add_attribute: Add global attributes (admin/role_manager)/admin/remove_attribute: Remove attributes with validation/role_manager/assign_attributes: Delegated attribute assignmentCrypto Module
aes.py: AES-256-CTR encryption with HMAC-SHA256 authentication
encrypt(): Stream-based file encryptiondecrypt(): Stream-based file decryption with integrity verificationabe_simulator.py: Policy-based access control
get_user_attributes(): Retrieves user attributes from users.jsoncheck_access(): Validates if user satisfies policy requirementsModular JavaScript Structure
The frontend follows a component-based architecture with three layers:
1. Components (static/shared/components/)
Reusable UI components:
modal.js: Generic modal dialog systemtoast.js: Toast notification componentnotification-manager.js: Centralized notification system2. Modules (static/shared/modules/)
Feature-specific functionality:
realtime-manager.js: WebSocket connection and event handlinguser-manager.js: User CRUD operationsattribute-manager.js: Global attribute managementpolicy-manager.js: File access policy managementfile-manager.js: Admin file managementdashboard-file-manager.js: User file listing and operationsupload-manager.js: File upload with policy definitionpassword-manager.js: Password change functionalityaudit-manager.js: Audit log viewing and filteringrole-manager.js: Role assignment interfacerole-manager-attribute.js: Delegated attribute assignment3. Utilities (static/shared/utils/)
Helper functions:
ui-helpers.js: Common UI manipulation functionsadmin-links.js: Admin navigation helpersDashboard-Specific Assets
admin/: Admin dashboard CSS, JS, and Tailwind configdashboard/: User dashboard CSS, JS, and Tailwind configcommon/: Favicons, PWA manifest, iconsJSON-Based Storage
Simple, file-based data persistence:
users.json - User accounts with attributes and passwords
{
"username": {
"attributes": ["attr1", "attr2"],
"password": "hashed_password"
}
}
attributes.json - Global attribute pool
["finance", "engineering", "hr", "executive"]
policies.json - File access policies
{
"encrypted_filename.enc": {
"policy": ["finance", "executive"],
"key": "encrypted_file_key",
"uploader": "admin",
"timestamp": "2025-11-07 10:30:45"
}
}
audit_logs.jsonl - Activity logs (JSON Lines format)
{"user": "admin", "action": "add_user", "details": "Added user: john", "time": "2025-11-07 10:30:45", "ip": "127.0.0.1"}
File Upload Flow:
/upload endpointapp/uploads/policies.jsonFile Download Flow:
/download/<filename>policies.jsonReal-Time Update Flow:
audit_logs.jsonlAttribute-Based Access Control:
Role-Based Administration:
Audit Trail:
The application features a well-structured dashboard system with separated concerns:
Located at /admin, provides comprehensive administrative functionality:
Features:
Structure:
app/static/admin/
βββ admin.css # Admin-specific styles
βββ admin-dashboard.js # Main admin controller
βββ tailwind.config.js # Tailwind configuration
Located at /dashboard, provides user-facing functionality:
Features:
Structure:
app/static/dashboard/
βββ dashboard.css # User dashboard styles
βββ dashboard.js # Main dashboard controller
βββ dashboard-tailwind.config.js # Tailwind configuration
Reusable components and modules used across both dashboards:
app/static/shared/
βββ components/ # UI components
β βββ modal.js # Generic modal system
β βββ toast.js # Toast notifications
β βββ notification-manager.js
βββ modules/ # Feature modules
β βββ realtime-manager.js # WebSocket handling
β βββ user-manager.js # User CRUD
β βββ attribute-manager.js
β βββ policy-manager.js
β βββ file-manager.js
β βββ upload-manager.js
β βββ password-manager.js
β βββ audit-manager.js
β βββ role-manager.js
β βββ role-manager-attribute.js
β βββ dashboard-file-manager.js
βββ utils/ # Helper utilities
βββ ui-helpers.js
βββ admin-links.js
GET / - Login pagePOST /login - User authenticationGET /logout - End user sessionGET /dashboard - Main user dashboard (shows accessible files)GET /api/files - Get list of files user can access (JSON)POST /change_password - Change user passwordPOST /upload - Upload and encrypt file with policyGET /download/<filename> - Download and decrypt filePOST /delete_file - Delete userβs uploaded fileGET /admin - Admin dashboardPOST /admin/add_user - Create new userPOST /admin/edit_user/<user_id> - Update user informationGET /admin/delete_user/<user_id> - Delete single user (legacy)POST /admin/delete_user - Delete user with audit logPOST /admin/bulk_delete_users - Delete multiple usersPOST /admin/update_user_roles - Assign roles to usersPOST /admin/bulk_set_attrs - Bulk assign attributes to usersPOST /admin/add_policy - Create file access policyPOST /admin/edit_policy/<file> - Update file policyGET /admin/delete_policy/<file> - Delete single policy (legacy)POST /admin/delete_policy - Delete policy with audit logPOST /admin/bulk_delete_policies - Delete multiple policiesPOST /admin/delete_file - Admin delete file with policyPOST /admin/add_attribute - Add global attributePOST /admin/remove_attribute - Remove global attributePOST /role_manager/assign_attributes - Role manager attribute assignmentGET /admin/download_audit_logs - Export audit logs (JSON)Connection Events:
connect - Client connection establisheddisconnect - Client disconnectedjoin_admin - Join admin updates roomleave_admin - Leave admin updates roomjoin_dashboard - Join dashboard updates roomleave_dashboard - Leave dashboard updates roomServer-Emitted Events:
user_added - New user createduser_updated - User information changeduser_deleted - User removedusers_bulk_deleted - Multiple users deleteduser_attributes_updated - User attributes changedpolicy_added - New file policy createdpolicy_updated - Policy modifiedpolicy_deleted - Policy removedpolicies_bulk_deleted - Multiple policies deletedattribute_added - Global attribute addedattribute_removed - Global attribute removedaudit_log_added - New audit log entryfile_deleted - File removed# Emit events after data changes
from flask import current_app
socketio = current_app.extensions.get('socketio')
utils.emit_socketio_event(socketio, 'custom_event', data, room='admin_updates')
// Listen for events and update UI
socket.on('custom_event', function(data) {
updateUIElement(data);
showToast('Action completed', 'success');
});
user_added not uapolicy_updated not updatedfile_deleted not file_deleteTesting Real-Time Features:
Open multiple browser tabs as admin to see live synchronization:
Testing File Access Control:
We welcome contributions from the community! Whether itβs fixing a bug, improving documentation, or adding a new feature, all contributions are welcome.
git clone https://github.com/<your-username>/kosh.git
cd kosh
git remote add upstream https://github.com/neelshha/kosh.git
git checkout -b feature/<short-description>
Follow Conventional Commits:
<type>: <short description>
feat: add real-time file upload progress
fix: resolve WebSocket connection issues
docs: update installation instructions
refactor: restructure dashboard components
style: formatting changes, no code logic updates
test: adding or updating tests
Use our GitHub issue templates for:
git push origin feature/<branch-name>
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright (c) 2025 Kavish Shah
Kosh is designed for educational purposes and internal LAN use. It should not be exposed to the public internet without proper security hardening, including:
The authors are not responsible for any data loss, security breaches, or other issues arising from the use of this software.
Special thanks to all contributors who have helped make Kosh better:
Kosh was created as a capstone project to demonstrate:
For questions, bug reports, or feature requests:
Scenario: Share financial reports only with finance and executive teams
finance, executivefinanceexecutive, financefinance, executiveScenario: Share project files with team members
project_alpha, engineering, designproject_alpha, designproject_alpha, engineeringScenario: HR manager needs to assign attributes to employees
role_manager role to HR userProblem: ModuleNotFoundError or import errors
Solution:
# Ensure you're in the virtual environment
source venv/bin/activate # On macOS/Linux
venv\Scripts\activate # On Windows
# Reinstall dependencies
pip install -r requirements.txt
Problem: Application only accessible from localhost
Solution:
KOSH_HOST=0.0.0.0 (binds to all interfaces)http://<server-ip>:7130Problem: Large file uploads fail or timeout
Solution:
app/uploads/ALLOWED_EXTENSIONSProblem: Real-time updates stop working
Solution:
Problem: audit_logs.jsonl consuming too much disk space
Solution:
KOSH_AUDIT_RETENTION_DAYS to shorter periodProblem: Forgot admin password
Solution:
data/users.json{
"admin": {
"attributes": [],
"password": "pass"
}
}
admin / passProblem: Canβt create files in data/ or app/uploads/
Solution:
# Fix directory permissions
chmod 755 data/
chmod 755 app/uploads/
Problem: Admin dashboard doesnβt update in real-time
Solution:
Planned enhancements for future versions:
Contributions welcome! If youβd like to work on any of these features, please create an issue or submit a pull request.
Happy file sharing with Kosh! ππ