Secret Notes Go Backend
π A secure, self-hosted notes application with end-to-end encryption for both text notes and file attachments. Built with Go and PocketBase, featuring passphrase-based encryption using AES-256-GCM.
β¨ Features
- π End-to-End Encryption: All notes and files encrypted with AES-256-GCM
- π Passphrase-Based Security: No accounts needed - your passphrase is your key
- π Encrypted File Storage: Upload and encrypt any file type
- π Self-Hosted: Deploy on your own infrastructure
- β‘ Fast & Lightweight: Built with Go and PocketBase
- π RESTful API: Easy integration with any frontend
- π± Stateless Design: No sessions or stored authentication tokens
π‘οΈ How Secure Is Your Data?
π Your Data is Completely Private
Even if someone gains full access to the server, database, and all files, they CANNOT read your data without your passphrase.
Here's why:
π Military-Grade Encryption
- AES-256-GCM: The same encryption standard used by governments and banks
- Authenticated Encryption: Prevents tampering - any modification breaks decryption
- Unique Per-Operation: Every note and file gets its own random salt and nonce
π Zero-Knowledge Architecture
- Server Cannot Decrypt: The server never sees your passphrase or decrypted data
- No Master Keys: There are no "backdoors" or recovery mechanisms
- Client-Side Key Derivation: Your passphrase becomes the encryption key using PBKDF2
π‘οΈ What Gets Stored
β
Encrypted Data: [random_salt][random_nonce][encrypted_content]
β
Passphrase Hash: SHA-256 hash for lookup (cannot be reversed)
β
Metadata: File names, content types (not sensitive)
β Your Passphrase: NEVER stored anywhere
β Decrypted Content: NEVER touches the database
β Encryption Keys: Generated on-demand, never stored
π Security Verification
- Open Source: All encryption code is visible and auditable
- Standard Libraries: Uses Go's crypto package (not custom crypto)
- No Network Transmission: Decryption happens server-side, only encrypted data in database
π¨ What This Means For You
β
If the server is hacked: Your data remains encrypted and unreadable
β
If the database is stolen: Attackers get encrypted gibberish
β
If we're subpoenaed: We literally cannot provide your data
β
If you forget your passphrase: Your data is permanently lost (by design)
β οΈ Your Responsibilities
- Use a strong passphrase (prefer long and random; minimum 3 characters enforced by API)
- Never share your passphrase with anyone
- Use HTTPS in production (to protect passphrase in transit)
- Keep backups if you want to preserve data
π¬ Technical Security Details
- PBKDF2: 100,000 iterations with SHA-256 for key derivation
- Random Generation: Uses crypto/rand for all random values
- Memory Safety: Go prevents buffer overflows and memory leaks
- Constant-Time Operations: Prevents timing attacks
- No Logging: Passphrases and decrypted content never logged
π Quick Start
Prerequisites
Installation
-
Clone the repository:
git clone https://github.com/yourusername/secret-notes-go.git
cd secret-notes-go
-
Install dependencies:
go mod download
-
Run the server:
go run main.go serve
-
Access the API:
- Server runs on
http://localhost:8090
- API endpoints available at
/api/secretnotes/
- Admin UI available at
http://localhost:8090/_/
π API Documentation
Authentication
No traditional authentication required. All operations use a passphrase (minimum 3 characters) that serves as both identifier and encryption key.
Core Endpoints
Notes
GET /api/secretnotes/notes/{phrase} - Get or create note
POST /api/secretnotes/notes/{phrase} - Create new note
PATCH /api/secretnotes/notes/{phrase} - Update note
Files
POST /api/secretnotes/notes/{phrase}/image - Upload encrypted file
GET /api/secretnotes/notes/{phrase}/image - Download decrypted file
DELETE /api/secretnotes/notes/{phrase}/image - Delete file
Example Usage
# Create a note
curl -X POST "http://localhost:8090/api/secretnotes/notes/your-very-long-secure-passphrase-here" \
-H "Content-Type: application/json" \
-d '{"title":"My Note","message":"Secret content"}'
# Upload a file
curl -X POST "http://localhost:8090/api/secretnotes/notes/your-very-long-secure-passphrase-here/image" \
-F "image=@document.pdf"
# Download the file
curl "http://localhost:8090/api/secretnotes/notes/your-very-long-secure-passphrase-here/image" \
-o downloaded-document.pdf
ποΈ Architecture
.
βββ main.go # Main application entry point
βββ migrations/
β βββ 001_init.go # Database schema migrations
βββ models/
β βββ encrypted_file.go # File model definitions
β βββ note.go # Note model definitions
βββ services/
β βββ encryption.go # AES-256-GCM encryption service
β βββ file.go # File handling service
β βββ note.go # Note management service
βββ middleware/
β βββ validation.go # Request validation middleware
βββ BACKEND_DOCS.md # Detailed API documentation
βββ FRONTEND_GUIDE.md # Frontend integration guide
π§ Configuration
Environment Variables
PORT: Server port (default: 8090)
DATA_DIR: Data directory for PocketBase (default: ./pb_data)
Production Deployment
- Use HTTPS: Always deploy behind HTTPS in production
- Secure Headers: Configure proper security headers
- Firewall: Restrict access to necessary ports only
- Backups: Regular backup of the
pb_data directory
- Monitoring: Set up logging and monitoring
π Documentation
π§ͺ Development
Running Tests
go test ./services/...
Database Reset
rm -rf pb_data/
go run main.go serve
Adding New Endpoints
- Add route in
main.go
- Implement handler function
- Update documentation
- Add tests
π€ Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Make your changes
- Add tests if applicable
- Update documentation
- Submit a pull request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
β οΈ Security Considerations
- Passphrase Strength: Use strong, unique passphrases (longer is better)
- HTTPS Only: Never use over unencrypted connections in production
- Regular Updates: Keep dependencies updated
- Backup Security: Encrypt backups and store securely
- Access Control: Implement proper network-level access controls
π Support
For security issues, please see SECURITY.md.
For general questions and support:
- Open an issue on GitHub
- Check the documentation in
BACKEND_DOCS.md
- Review the frontend integration guide in
FRONTEND_GUIDE.md
Built with β€οΈ using Go and PocketBase
secretnotes-go-backend