Skip to content

ravadasashank/secure-cloud-file-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Secure Cloud File Server πŸ”’

A production-ready, secure cloud-based file server API built with Node.js, featuring end-to-end encryption, JWT authentication, and cloud storage integration.

🌟 Features

  • Secure Authentication: JWT-based user authentication with bcrypt password hashing
  • End-to-End Encryption: AES-256-GCM encryption for file data at rest
  • Cloud Storage: Integration with AWS S3 for scalable file storage
  • RESTful API: Well-structured API endpoints following REST principles
  • Rate Limiting: Protection against brute force attacks
  • Input Validation: Comprehensive request validation using express-validator
  • Error Handling: Centralized error handling middleware
  • Security Headers: Helmet.js for setting secure HTTP headers
  • CORS Support: Configurable Cross-Origin Resource Sharing
  • File Management: Upload, download, delete, and share files securely

πŸ› οΈ Tech Stack

  • Runtime: Node.js (v16+)
  • Framework: Express.js
  • Database: MongoDB with Mongoose ODM
  • Authentication: JWT (JSON Web Tokens)
  • Encryption: Node.js Crypto (AES-256-GCM)
  • Cloud Storage: AWS SDK (S3)
  • Security: Helmet, bcryptjs, express-rate-limit
  • Validation: express-validator
  • File Upload: Multer

πŸ“‹ Prerequisites

  • Node.js (v16.0.0 or higher)
  • npm (v8.0.0 or higher)
  • MongoDB instance (local or cloud)
  • AWS S3 bucket (for file storage)

πŸš€ Installation

  1. Clone the repository:
git clone https://github.com/ravadasashank/secure-cloud-file-server.git
cd secure-cloud-file-server
  1. Install dependencies:
npm install
  1. Create a .env file in the root directory:
NODE_ENV=development
PORT=3000

# Database
MONGODB_URI=mongodb://localhost:27017/secure-file-server

# Authentication
JWT_SECRET=your_jwt_secret_key_here

# AWS Configuration
AWS_ACCESS_KEY_ID=your_aws_access_key
AWS_SECRET_ACCESS_KEY=your_aws_secret_key
AWS_REGION=us-east-1
AWS_S3_BUCKET=your-bucket-name

# CORS
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5173
  1. Start the development server:
npm run dev

πŸ“ Project Structure

secure-cloud-file-server/
β”œβ”€β”€ src/
β”‚   └── app.js                 # Express app entry point
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ authRoutes.js          # Authentication routes
β”‚   └── fileRoutes.js          # File management routes
β”œβ”€β”€ controllers/
β”‚   β”œβ”€β”€ authController.js      # Authentication logic
β”‚   └── fileController.js      # File operations logic
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ userService.js         # User database operations
β”‚   β”œβ”€β”€ fileService.js         # File database operations
β”‚   β”œβ”€β”€ storageService.js      # Cloud storage operations
β”‚   └── encryptionService.js   # Encryption/decryption utilities
β”œβ”€β”€ middleware/
β”‚   β”œβ”€β”€ auth.js                # JWT authentication middleware
β”‚   β”œβ”€β”€ upload.js              # File upload middleware
β”‚   β”œβ”€β”€ validation.js          # Input validation middleware
β”‚   └── errorHandler.js        # Global error handler
β”œβ”€β”€ utils/
β”‚   └── helpers.js             # Utility functions
β”œβ”€β”€ .gitignore
β”œβ”€β”€ package.json
└── README.md

πŸ”‘ API Endpoints

Authentication

Register User

POST /api/auth/register
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "SecurePassword123",
  "name": "John Doe"
}

Login

POST /api/auth/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "SecurePassword123"
}

Get Profile

GET /api/auth/profile
Authorization: Bearer <token>

File Management

Upload File

POST /api/files/upload
Authorization: Bearer <token>
Content-Type: multipart/form-data

file: <binary_data>

Get All Files

GET /api/files
Authorization: Bearer <token>

Download File

GET /api/files/:id/download
Authorization: Bearer <token>

Delete File

DELETE /api/files/:id
Authorization: Bearer <token>

Share File

PUT /api/files/:id/share
Authorization: Bearer <token>
Content-Type: application/json

{
  "email": "recipient@example.com"
}

πŸ”’ Security Features

  • Password Hashing: Bcrypt with salt rounds for secure password storage
  • JWT Tokens: Signed tokens with expiration for stateless authentication
  • File Encryption: AES-256-GCM encryption for all uploaded files
  • Rate Limiting: 100 requests per 15 minutes per IP address
  • Input Validation: All inputs validated before processing
  • Secure Headers: Helmet.js for setting security-related HTTP headers
  • CORS Protection: Configurable origin whitelist
  • Error Sanitization: No sensitive information leaked in error responses

πŸ§ͺ Testing

# Run tests with coverage
npm test

# Run linter
npm run lint

πŸ“ Environment Variables

Variable Description Required
NODE_ENV Environment (development/production) Yes
PORT Server port Yes
MONGODB_URI MongoDB connection string Yes
JWT_SECRET Secret key for JWT signing Yes
AWS_ACCESS_KEY_ID AWS access key Yes
AWS_SECRET_ACCESS_KEY AWS secret key Yes
AWS_REGION AWS region Yes
AWS_S3_BUCKET S3 bucket name Yes
ALLOWED_ORIGINS Comma-separated CORS origins No

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License.

πŸ‘€ Author

Ravada Sashank

πŸ™ Acknowledgments

  • Express.js community for excellent middleware
  • MongoDB for scalable database solutions
  • AWS for reliable cloud storage
  • Node.js crypto module for encryption capabilities

Note: Never commit your .env file or any files containing sensitive information. Always use environment variables for configuration.

About

Secure file-sharing Node.js API with S3/MongoDB/AES/JWT

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors