Skip to content

Commit b6825fc

Browse files
authored
Merge pull request #8 from typelets/feature/web-socket
feat: implement WebSocket real-time sync with HMAC message authentication
2 parents 7185f3b + 469bfa9 commit b6825fc

26 files changed

+3977
-470
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
- 🌙 **Dark/Light mode** - Easy on the eyes, day or night
6464
- 📎 **File attachments** - Upload and encrypt files up to 10MB per file
6565
- 📊 **Usage tracking** - Monitor storage and notes limits with visual progress indicators
66-
- 📱 **Responsive design** - Works seamlessly on desktop and mobile
66+
- 🌐 **Cross-platform** - Responsive web app that works seamlessly on desktop, tablet, and mobile
6767
- 🖨️ **Print support** - Clean printing with proper formatting
6868

6969
## 🔒 Security First
@@ -86,6 +86,7 @@ Your encryption keys are derived from your master password. Even if our database
8686

8787
For complete security details and technical implementation, see our [**Security Documentation →**](./SECURITY.md)
8888

89+
8990
## 🚀 Quick Start
9091

9192
### Prerequisites

SECURITY.md

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview
44

5-
Typelets implements a **zero-knowledge encryption architecture** where all note encryption and decryption happens exclusively in your browser. We cannot read your notes - even if we wanted to. This document details our security implementation for transparency and verification.
5+
Typelets implements a **zero-knowledge encryption architecture** with **cryptographic message authentication** for real-time sync. All note encryption and decryption happens exclusively in your browser, and all real-time communications are cryptographically authenticated. We cannot read your notes - even if we wanted to. This document details our complete security implementation for transparency and verification.
66

77
## Core Security Principles
88

@@ -18,6 +18,12 @@ Typelets implements a **zero-knowledge encryption architecture** where all note
1818
- No master keys exist that could decrypt all user data
1919
- Password reset means permanent data loss (by design)
2020

21+
### 3. Cryptographic Message Authentication
22+
- Real-time WebSocket messages are HMAC-SHA256 signed
23+
- Session secrets derived from JWT tokens prevent tampering
24+
- Timestamp + nonce protection against replay attacks
25+
- Message integrity verified on both client and server
26+
2127
## Technical Implementation
2228

2329
### Encryption Algorithm
@@ -119,14 +125,46 @@ graph LR
119125
- **Token-based API access**: No passwords stored
120126
- **Automatic token refresh**: Seamless security updates
121127

128+
### Real-Time Sync Security
129+
130+
**WebSocket Message Authentication (HMAC-SHA256)**
131+
```
132+
Algorithm: HMAC-SHA256
133+
Session Secret: Derived from JWT + User ID + Timestamp
134+
Message Replay Protection: 5-minute maximum age
135+
Nonce-based Uniqueness: Cryptographic random nonces
136+
```
137+
138+
**Message Authentication Flow**
139+
```javascript
140+
// Outgoing Message Structure
141+
{
142+
payload: { type: "note_update", noteId: "123", changes: {...} },
143+
signature: "hmac_sha256_signature...",
144+
timestamp: 1640995200000,
145+
nonce: "cryptographic_random_string"
146+
}
147+
```
148+
149+
**Security Features**
150+
- **Message Integrity**: HMAC-SHA256 prevents tampering
151+
- **Authenticity Verification**: Proves message origin
152+
- **Replay Attack Prevention**: Timestamp + nonce protection
153+
- **Session-based Authentication**: Unique secrets per connection
154+
- **Graceful Degradation**: Works without backend support
155+
122156
## Attack Mitigation
123157

124158
### What We Protect Against
125159

126160
| Attack Vector | Protection Method |
127161
|--------------|------------------|
128162
| Server breach | Encrypted data only - no readable content |
129-
| Man-in-the-middle | HTTPS + encrypted payload |
163+
| Man-in-the-middle | HTTPS + encrypted payload + message authentication |
164+
| Message tampering | HMAC-SHA256 signature verification |
165+
| Replay attacks | Timestamp validation + cryptographic nonces |
166+
| WebSocket MITM | Session-based message authentication |
167+
| Message forgery | HMAC signature proves authenticity |
130168
| Rainbow tables | Per-note salts (128-bit) |
131169
| Brute force | 250,000 PBKDF2 iterations |
132170
| Key reuse | Unique IV per encryption |
@@ -142,6 +180,7 @@ graph LR
142180
- Weak master passwords (if used)
143181
- Browser vulnerabilities
144182
- Users who lose their encryption keys
183+
- WebSocket message authentication requires backend support (graceful fallback without)
145184

146185
## User Experience & Security Flow
147186

@@ -172,6 +211,21 @@ Login → Enter Master Password → Access Notes → Auto-lock on Session End
172211
4. Verify `title` and `content` show as `[ENCRYPTED]`
173212
5. Verify presence of `encryptedTitle`, `encryptedContent`, `iv`, `salt`
174213

214+
### Test Message Authentication
215+
1. Open browser DevTools → Console tab
216+
2. Look for "Message authentication initialized" on WebSocket connection
217+
3. Edit a note in real-time
218+
4. Check WebSocket messages for signature structure:
219+
```json
220+
{
221+
"payload": { "type": "note_update", ... },
222+
"signature": "base64_hmac_signature",
223+
"timestamp": 1640995200000,
224+
"nonce": "random_string"
225+
}
226+
```
227+
5. Verify "Message signed successfully" in console logs
228+
175229
### Verify Zero-Knowledge
176230
```sql
177231
-- Even with database access, you see only:
@@ -230,7 +284,13 @@ SELECT encryptedTitle FROM notes;
230284
**Security vs Performance balance.** This provides ~0.5 seconds of computation on modern devices while exceeding OWASP recommendations.
231285

232286
### Q: What about quantum computers?
233-
**AES-256 is quantum-resistant** with effective 128-bit security against Grover's algorithm. We'll migrate to post-quantum algorithms when standardized.
287+
**AES-256 is quantum-resistant** with effective 128-bit security against Grover's algorithm. HMAC-SHA256 is also quantum-resistant. We'll migrate to post-quantum algorithms when standardized.
288+
289+
### Q: How does WebSocket message authentication work?
290+
**Each real-time message is cryptographically signed** using HMAC-SHA256 with a session secret derived from your JWT token. This prevents message tampering, replay attacks, and ensures authenticity of real-time updates.
291+
292+
### Q: What happens if message authentication fails?
293+
**The message is rejected and logged as a security event.** Your app continues working normally, but you're protected from potentially malicious messages. The frontend gracefully handles authentication failures.
234294

235295
## Security Disclosure
236296

@@ -251,4 +311,15 @@ For security-related questions:
251311

252312
---
253313

254-
**Remember**: True security means even we cannot access your data. Your privacy is not a feature - it's our foundation.
314+
**Remember**: True security means even we cannot access your data AND cannot tamper with your real-time communications. Your privacy and data integrity are not features - they're our foundation.
315+
316+
## Security Summary
317+
318+
Typelets provides **defense-in-depth** with multiple layers of cryptographic protection:
319+
320+
1. **Storage Layer**: AES-256-GCM client-side encryption with zero-knowledge architecture
321+
2. **Transport Layer**: HMAC-SHA256 message authentication for real-time sync integrity
322+
3. **Session Layer**: JWT-based authentication with automatic token refresh
323+
4. **Application Layer**: Memory-safe key management with automatic cleanup
324+
325+
This makes Typelets one of the most secure note-taking platforms available, with both **storage encryption** and **transport authentication** cryptographically protected.

0 commit comments

Comments
 (0)