securequ 1.1.19 → 1.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/Base.cjs +146 -146
- package/client/Base.cjs.map +1 -1
- package/client/Base.d.ts +18 -18
- package/client/Base.js +146 -146
- package/client/Base.js.map +1 -1
- package/client/index.cjs +155 -138
- package/client/index.cjs.map +1 -1
- package/client/index.d.ts +10 -10
- package/client/index.js +156 -139
- package/client/index.js.map +1 -1
- package/client/types.d.ts +39 -35
- package/include/compress.cjs +31 -31
- package/include/compress.cjs.map +1 -1
- package/include/compress.d.ts +9 -9
- package/include/compress.js +33 -33
- package/include/compress.js.map +1 -1
- package/include/crypto.cjs +132 -132
- package/include/crypto.cjs.map +1 -1
- package/include/crypto.d.ts +21 -21
- package/include/crypto.js +132 -132
- package/include/crypto.js.map +1 -1
- package/include/file-scaner.cjs +77 -95
- package/include/file-scaner.cjs.map +1 -1
- package/include/file-scaner.d.ts +11 -11
- package/include/file-scaner.js +74 -95
- package/include/file-scaner.js.map +1 -1
- package/include/file.cjs +78 -60
- package/include/file.cjs.map +1 -1
- package/include/file.js +78 -61
- package/include/file.js.map +1 -1
- package/index.cjs +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/readme.md +312 -312
- package/server/Base.cjs +105 -105
- package/server/Base.cjs.map +1 -1
- package/server/Base.d.ts +20 -20
- package/server/Base.js +105 -105
- package/server/Base.js.map +1 -1
- package/server/Router.cjs +29 -29
- package/server/Router.cjs.map +1 -1
- package/server/Router.d.ts +7 -7
- package/server/Router.js +29 -29
- package/server/Router.js.map +1 -1
- package/server/index.cjs +185 -187
- package/server/index.cjs.map +1 -1
- package/server/index.d.ts +5 -5
- package/server/index.js +186 -188
- package/server/index.js.map +1 -1
- package/server/types.d.ts +72 -72
package/readme.md
CHANGED
|
@@ -1,312 +1,312 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
|
|
3
|
-
# securequ
|
|
4
|
-
|
|
5
|
-
High‑level encrypted & compressed HTTP request + chunked upload toolkit for browser ↔ server applications.
|
|
6
|
-
|
|
7
|
-
</div>
|
|
8
|
-
|
|
9
|
-
> Provides an additional application‑layer privacy/integrity envelope. Always deploy behind HTTPS.
|
|
10
|
-
|
|
11
|
-
<p align="center">
|
|
12
|
-
<a href="https://www.npmjs.com/package/securequ"><img src="https://img.shields.io/npm/v/securequ.svg" alt="npm version" /></a>
|
|
13
|
-
<a href="#"><img src="https://img.shields.io/badge/status-active-green" alt="status" /></a>
|
|
14
|
-
<a href="#security"><img src="https://img.shields.io/badge/focus-security-blue" alt="focus" /></a>
|
|
15
|
-
</p>
|
|
16
|
-
|
|
17
|
-
## Table of Contents
|
|
18
|
-
|
|
19
|
-
- [securequ](#securequ)
|
|
20
|
-
- [Table of Contents](#table-of-contents)
|
|
21
|
-
- [Overview](#overview)
|
|
22
|
-
- [Why securequ?](#why-securequ)
|
|
23
|
-
- [Core Concepts (Abstracted)](#core-concepts-abstracted)
|
|
24
|
-
- [Security (Summary)](#security-summary)
|
|
25
|
-
- [Performance Snapshot](#performance-snapshot)
|
|
26
|
-
- [Install](#install)
|
|
27
|
-
- [Minimal Server (Express)](#minimal-server-express)
|
|
28
|
-
- [Minimal Client](#minimal-client)
|
|
29
|
-
- [Client Hooks (Selected)](#client-hooks-selected)
|
|
30
|
-
- [API Surface (High Level)](#api-surface-high-level)
|
|
31
|
-
- [Server Response Model](#server-response-model)
|
|
32
|
-
- [File Upload Overview](#file-upload-overview)
|
|
33
|
-
- [Configuration (Essentials)](#configuration-essentials)
|
|
34
|
-
- [Error Semantics](#error-semantics)
|
|
35
|
-
- [Performance Guidance](#performance-guidance)
|
|
36
|
-
- [Troubleshooting](#troubleshooting)
|
|
37
|
-
- [FAQ](#faq)
|
|
38
|
-
- [Versioning \& Stability](#versioning--stability)
|
|
39
|
-
- [Contributing](#contributing)
|
|
40
|
-
- [Security Reporting](#security-reporting)
|
|
41
|
-
- [Disclaimer](#disclaimer)
|
|
42
|
-
- [License](#license)
|
|
43
|
-
|
|
44
|
-
## Overview
|
|
45
|
-
|
|
46
|
-
securequ places a compact, binary, encrypted envelope around HTTP request/response bodies and coordinates secure, chunked file uploads. A lightweight, ephemeral token (internally named `signeture`) is established via a handshake per client origin and renewed automatically when necessary. Development mode keeps the ergonomics of plain JSON while production mode obfuscates both payload bodies and (optionally) query parameters.
|
|
47
|
-
|
|
48
|
-
Key capabilities:
|
|
49
|
-
- Application‑layer confidentiality & integrity (in addition to transport‑layer TLS)
|
|
50
|
-
- Binary serialization + compression for efficient payload transfer
|
|
51
|
-
- Short‑lived opaque token automatically refreshed
|
|
52
|
-
- File uploads with controlled chunk sizing, size limits, optional first‑chunk file‑type validation, and progress events
|
|
53
|
-
- Minimal routing utilities and lifecycle hooks—framework agnostic
|
|
54
|
-
- Consistent TypeScript surface
|
|
55
|
-
|
|
56
|
-
## Why securequ?
|
|
57
|
-
|
|
58
|
-
| Need | Plain fetch + JSON | securequ |
|
|
59
|
-
| --------------------------------------------- | -------------------- | ---------------------- |
|
|
60
|
-
| Hide request structure from casual inspection | ✗ | ✓ (encrypted envelope) |
|
|
61
|
-
| Automatic compression + binary serialization | Partial (manual) | ✓ built‑in |
|
|
62
|
-
| Short‑lived opaque request token | Custom work | ✓ baked in |
|
|
63
|
-
| Client lifecycle hooks | Manual wiring | ✓ hooks API |
|
|
64
|
-
| Validated chunked uploads + progress | Manual / library mix | ✓ integrated |
|
|
65
|
-
|
|
66
|
-
Use it when you want an extra (opaque) layer plus structured uploads without re‑inventing crypto + binary packing. If HTTPS + standard auth covers all your needs and you prefer transparency, you may not need this.
|
|
67
|
-
|
|
68
|
-
## Core Concepts (Abstracted)
|
|
69
|
-
|
|
70
|
-
| Concept | Summary |
|
|
71
|
-
| ------------------ | --------------------------------------------------------------------------------------- |
|
|
72
|
-
| Pre‑shared secret | Static value per allowed origin (server‑side registration) |
|
|
73
|
-
| Handshake | Lightweight exchange producing a short‑lived opaque token (auto refreshed) |
|
|
74
|
-
| Encrypted envelope | Bodies (and in production, query params) serialized → compressed → encrypted |
|
|
75
|
-
| Development mode | Skips encryption for non‑handshake application requests to aid debugging |
|
|
76
|
-
| Hooks | Extensibility points for request & upload lifecycle events |
|
|
77
|
-
| Chunked upload | Deterministic splitting + metadata negotiation + ordered transfer + completion callback |
|
|
78
|
-
|
|
79
|
-
## Security (Summary)
|
|
80
|
-
|
|
81
|
-
Implemented (High Level):
|
|
82
|
-
- Symmetric encryption with authenticated integrity (AEAD style)
|
|
83
|
-
- Short token lifetime, minimizing replay viability
|
|
84
|
-
- Payload and (production) query obfuscation
|
|
85
|
-
- Optional file‑type validation via first‑chunk signature scanning
|
|
86
|
-
|
|
87
|
-
Operator Responsibilities:
|
|
88
|
-
- Enforce HTTPS and standard secure headers
|
|
89
|
-
- Generate long, random client secrets and rotate periodically
|
|
90
|
-
- Layer proper authentication/authorization (sessions, tokens, etc.)
|
|
91
|
-
- Validate and sanitize business data in handlers
|
|
92
|
-
|
|
93
|
-
Out of Scope:
|
|
94
|
-
- Forward secrecy / per‑message key rotation
|
|
95
|
-
- Fine‑grained end‑user authentication
|
|
96
|
-
- True streaming (payloads are presently buffered)
|
|
97
|
-
- Built‑in rate limiting / abuse controls
|
|
98
|
-
|
|
99
|
-
## Performance Snapshot
|
|
100
|
-
|
|
101
|
-
- Compression + binary encoding reduce large structured bodies vs raw JSON
|
|
102
|
-
- Overhead is minimal for medium/large payloads; for tiny payloads (< 200B) you may prefer plain requests
|
|
103
|
-
- Chunk size is adaptive (you can override) to balance memory and progress smoothness
|
|
104
|
-
- File type detection (if enabled) inspects only the first chunk
|
|
105
|
-
|
|
106
|
-
## Install
|
|
107
|
-
|
|
108
|
-
```bash
|
|
109
|
-
npm install securequ
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
Peer/runtime deps are installed automatically (libsodium, fflate, msgpackr, path-to-regexp, xanfetch).
|
|
113
|
-
|
|
114
|
-
## Minimal Server (Express)
|
|
115
|
-
|
|
116
|
-
```ts
|
|
117
|
-
import express from 'express';
|
|
118
|
-
import { SecurequServer } from 'securequ';
|
|
119
|
-
|
|
120
|
-
const api = new SecurequServer({
|
|
121
|
-
mode: 'production',
|
|
122
|
-
basepath: '/api',
|
|
123
|
-
clients: [{ origin: 'https://app.example.com' | "*", secret: process.env.APP_CLIENT_SECRET! }],
|
|
124
|
-
upload: {
|
|
125
|
-
chunk: async (chunk, meta) => { /* store chunk */ return true; },
|
|
126
|
-
complete: async (meta) => { /* stitch & persist */ return `/files/${meta.fileid}`; },
|
|
127
|
-
failed: async (meta) => boolean
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
api.post('/echo', ({ body }) => { throw { ok: true, body }; });
|
|
132
|
-
|
|
133
|
-
const app = express();
|
|
134
|
-
app.use('/api/*', express.raw({ type: 'application/octet-stream', limit: '20mb' }), async (req, res) => {
|
|
135
|
-
const r = await api.listen(req.originalUrl, {
|
|
136
|
-
body: req.body,
|
|
137
|
-
headers: req.headers,
|
|
138
|
-
}, req);
|
|
139
|
-
res.status(r.status).end(r.content);
|
|
140
|
-
});
|
|
141
|
-
app.listen(4000);
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
## Minimal Client
|
|
145
|
-
|
|
146
|
-
```ts
|
|
147
|
-
import { SecurequClient } from 'securequ';
|
|
148
|
-
|
|
149
|
-
const client = new SecurequClient({
|
|
150
|
-
url: 'https://api.example.com/api',
|
|
151
|
-
secret: '<client-secret>'
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// Simple request
|
|
155
|
-
const res = await client.post('echo', { body: { hello: 'world' } });
|
|
156
|
-
console.log(res);
|
|
157
|
-
|
|
158
|
-
// File upload with progress
|
|
159
|
-
async function uploadFile(file: File) {
|
|
160
|
-
const result = await client.upload(file, p => console.log('progress %', p));
|
|
161
|
-
console.log(result);
|
|
162
|
-
}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
## Client Hooks (Selected)
|
|
166
|
-
|
|
167
|
-
```ts
|
|
168
|
-
hooks: {
|
|
169
|
-
beforeRequest: (path, init) => init,
|
|
170
|
-
afterResponse: (resp) => {},
|
|
171
|
-
beforeUpload: (file, fileId) => file,
|
|
172
|
-
afterUpload: (response, file) => {},
|
|
173
|
-
beforeUploadChunk: (chunk, idx, total) => {},
|
|
174
|
-
afterUploadChunk: (resp, idx, total) => {},
|
|
175
|
-
}
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
## API Surface (High Level)
|
|
179
|
-
|
|
180
|
-
```ts
|
|
181
|
-
// Client
|
|
182
|
-
client.get(path, init?)
|
|
183
|
-
client.post(path, init?)
|
|
184
|
-
client.put(path, init?)
|
|
185
|
-
client.delete(path, init?)
|
|
186
|
-
client.upload(file, onProgress?)
|
|
187
|
-
|
|
188
|
-
// Server
|
|
189
|
-
server.get(path, handler)
|
|
190
|
-
server.post(path, handler)
|
|
191
|
-
server.put(path, handler)
|
|
192
|
-
server.delete(path, handler)
|
|
193
|
-
server.listen(url, listenerInfo)
|
|
194
|
-
|
|
195
|
-
// Utilities (optional direct use)
|
|
196
|
-
import { crypto, compresor } from 'securequ';
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Server Response Model
|
|
200
|
-
|
|
201
|
-
Handlers conclude by `throw`ing:
|
|
202
|
-
- Plain object / primitive → serialized (dev) or encrypted (prod) with 200 status
|
|
203
|
-
- `Response` instance → its status/body is used (still wrapped if necessary)
|
|
204
|
-
- `Error` → message returned with a not‑found style status (configurable via customization if you wrap upstream)
|
|
205
|
-
|
|
206
|
-
This pattern deliberately short‑circuits route evaluation and keeps handler code linear.
|
|
207
|
-
|
|
208
|
-
## File Upload Overview
|
|
209
|
-
|
|
210
|
-
- Client sends metadata first
|
|
211
|
-
- Server accepts and tracks state
|
|
212
|
-
- Client streams fixed‑size chunks sequentially
|
|
213
|
-
- Final chunk triggers assembly + returned path / identifier
|
|
214
|
-
- A failure notification allows cleanup
|
|
215
|
-
|
|
216
|
-
## Configuration (Essentials)
|
|
217
|
-
|
|
218
|
-
```ts
|
|
219
|
-
// Server
|
|
220
|
-
new SecurequServer({
|
|
221
|
-
mode: 'production' | 'development',
|
|
222
|
-
basepath: '/api',
|
|
223
|
-
clients: [{ origin, secret }],
|
|
224
|
-
upload?: { maxFilesize?, checkFileType?, chunk(), complete(), failed? },
|
|
225
|
-
accept?: (info: HandlerInfo, metadata?: Metadata) => boolean | Promise<boolean>
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
// Client
|
|
229
|
-
new SecurequClient({
|
|
230
|
-
url: 'https://host/api',
|
|
231
|
-
secret: '<pre-shared>',
|
|
232
|
-
chunkSize?: number,
|
|
233
|
-
hooks?: { ... }
|
|
234
|
-
});
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
## Error Semantics
|
|
238
|
-
|
|
239
|
-
- Success: `success: true`, `data` contains decrypted payload
|
|
240
|
-
- Expired token is auto‑recovered (one retry) by re-handshaking
|
|
241
|
-
- Server thrown `Error` surfaces message (wrapped) to client
|
|
242
|
-
|
|
243
|
-
## Performance Guidance
|
|
244
|
-
|
|
245
|
-
- Use production mode for real benchmarking (encryption path active)
|
|
246
|
-
- Keep secrets long & random (>= 32 chars)
|
|
247
|
-
- Tune `chunkSize` only if you need very granular progress events
|
|
248
|
-
|
|
249
|
-
## Troubleshooting
|
|
250
|
-
|
|
251
|
-
| Symptom | Possible Cause | Suggested Fix |
|
|
252
|
-
| -------------------------------- | ------------------------------------ | ----------------------------------------------------------------- |
|
|
253
|
-
| `Signeture expired` loops | Clock skew or token window too short | Ensure system clocks are synced; minimize artificial delays |
|
|
254
|
-
| Always 404 / Not found | Route not registered before `listen` | Register handlers before attaching middleware |
|
|
255
|
-
| Plain text visible in production | App running in development mode | Set `mode: 'production'` in server config |
|
|
256
|
-
| Upload stops mid‑way | Page navigation / tab close | Use `beforeunload` UI warning or resume strategy (future roadmap) |
|
|
257
|
-
| File type rejected | Magic bytes not recognized | Disable `checkFileType` or extend scanner if needed |
|
|
258
|
-
| High CPU for tiny payloads | Compression/encryption overhead | Bypass securequ for very small trivial requests |
|
|
259
|
-
|
|
260
|
-
If an issue isn’t listed: enable development mode locally to inspect raw (unencrypted) bodies for debugging, then switch back.
|
|
261
|
-
|
|
262
|
-
## FAQ
|
|
263
|
-
|
|
264
|
-
**Does this replace TLS?**
|
|
265
|
-
No. It layers *on top* of TLS.
|
|
266
|
-
|
|
267
|
-
**Can I plug into another HTTP framework?**
|
|
268
|
-
Yes—adapt the raw body + headers and call `server.listen()`.
|
|
269
|
-
|
|
270
|
-
**How do I add auth?**
|
|
271
|
-
Put your auth tokens/data *inside* the encrypted body or add middleware before calling `listen`.
|
|
272
|
-
|
|
273
|
-
**TypeScript support?**
|
|
274
|
-
Fully typed. Route handlers get a typed `info` object; client responses are typed with a generic shape (`SecurequClientResponse`).
|
|
275
|
-
|
|
276
|
-
**Can I inspect payloads in production?**
|
|
277
|
-
Not without decrypting. Use development mode locally when introspection is needed.
|
|
278
|
-
|
|
279
|
-
**Is there resume upload support?**
|
|
280
|
-
Not yet; planned. You can implement partial detection using hooks + server state.
|
|
281
|
-
|
|
282
|
-
**How big can files be?**
|
|
283
|
-
Limited by your configured `maxFilesize` (KB) and infrastructure memory / timeout constraints.
|
|
284
|
-
|
|
285
|
-
## Versioning & Stability
|
|
286
|
-
|
|
287
|
-
The project follows semantic versioning principles as features mature. Prior to a formal `1.x` stability declaration, minor releases may introduce carefully documented adjustments. Pin exact versions in sensitive production environments.
|
|
288
|
-
|
|
289
|
-
## Contributing
|
|
290
|
-
|
|
291
|
-
1. Fork & create a feature branch
|
|
292
|
-
2. Add or adjust tests where behavior changes
|
|
293
|
-
3. Ensure TypeScript builds without errors
|
|
294
|
-
4. Open a PR with a concise rationale
|
|
295
|
-
|
|
296
|
-
Please avoid including sensitive implementation details in public issue titles (describe at a high level instead).
|
|
297
|
-
|
|
298
|
-
## Security Reporting
|
|
299
|
-
|
|
300
|
-
If you believe you have discovered a vulnerability, please refrain from opening a public issue. Instead contact the maintainer privately (add a SECURITY.md for formal process if publishing broadly). Provide a minimal, reproducible scenario.
|
|
301
|
-
|
|
302
|
-
## Disclaimer
|
|
303
|
-
|
|
304
|
-
securequ provides an additional obfuscation + encryption layer. It is not a substitute for robust authentication, authorization, or transport security practices. Combine with TLS, secret rotation, and standard security controls.
|
|
305
|
-
|
|
306
|
-
## License
|
|
307
|
-
|
|
308
|
-
No license file included. Add one (e.g., MIT) before publishing publicly.
|
|
309
|
-
|
|
310
|
-
---
|
|
311
|
-
Issues & contributions welcome.
|
|
312
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# securequ
|
|
4
|
+
|
|
5
|
+
High‑level encrypted & compressed HTTP request + chunked upload toolkit for browser ↔ server applications.
|
|
6
|
+
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
> Provides an additional application‑layer privacy/integrity envelope. Always deploy behind HTTPS.
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/securequ"><img src="https://img.shields.io/npm/v/securequ.svg" alt="npm version" /></a>
|
|
13
|
+
<a href="#"><img src="https://img.shields.io/badge/status-active-green" alt="status" /></a>
|
|
14
|
+
<a href="#security"><img src="https://img.shields.io/badge/focus-security-blue" alt="focus" /></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
## Table of Contents
|
|
18
|
+
|
|
19
|
+
- [securequ](#securequ)
|
|
20
|
+
- [Table of Contents](#table-of-contents)
|
|
21
|
+
- [Overview](#overview)
|
|
22
|
+
- [Why securequ?](#why-securequ)
|
|
23
|
+
- [Core Concepts (Abstracted)](#core-concepts-abstracted)
|
|
24
|
+
- [Security (Summary)](#security-summary)
|
|
25
|
+
- [Performance Snapshot](#performance-snapshot)
|
|
26
|
+
- [Install](#install)
|
|
27
|
+
- [Minimal Server (Express)](#minimal-server-express)
|
|
28
|
+
- [Minimal Client](#minimal-client)
|
|
29
|
+
- [Client Hooks (Selected)](#client-hooks-selected)
|
|
30
|
+
- [API Surface (High Level)](#api-surface-high-level)
|
|
31
|
+
- [Server Response Model](#server-response-model)
|
|
32
|
+
- [File Upload Overview](#file-upload-overview)
|
|
33
|
+
- [Configuration (Essentials)](#configuration-essentials)
|
|
34
|
+
- [Error Semantics](#error-semantics)
|
|
35
|
+
- [Performance Guidance](#performance-guidance)
|
|
36
|
+
- [Troubleshooting](#troubleshooting)
|
|
37
|
+
- [FAQ](#faq)
|
|
38
|
+
- [Versioning \& Stability](#versioning--stability)
|
|
39
|
+
- [Contributing](#contributing)
|
|
40
|
+
- [Security Reporting](#security-reporting)
|
|
41
|
+
- [Disclaimer](#disclaimer)
|
|
42
|
+
- [License](#license)
|
|
43
|
+
|
|
44
|
+
## Overview
|
|
45
|
+
|
|
46
|
+
securequ places a compact, binary, encrypted envelope around HTTP request/response bodies and coordinates secure, chunked file uploads. A lightweight, ephemeral token (internally named `signeture`) is established via a handshake per client origin and renewed automatically when necessary. Development mode keeps the ergonomics of plain JSON while production mode obfuscates both payload bodies and (optionally) query parameters.
|
|
47
|
+
|
|
48
|
+
Key capabilities:
|
|
49
|
+
- Application‑layer confidentiality & integrity (in addition to transport‑layer TLS)
|
|
50
|
+
- Binary serialization + compression for efficient payload transfer
|
|
51
|
+
- Short‑lived opaque token automatically refreshed
|
|
52
|
+
- File uploads with controlled chunk sizing, size limits, optional first‑chunk file‑type validation, and progress events
|
|
53
|
+
- Minimal routing utilities and lifecycle hooks—framework agnostic
|
|
54
|
+
- Consistent TypeScript surface
|
|
55
|
+
|
|
56
|
+
## Why securequ?
|
|
57
|
+
|
|
58
|
+
| Need | Plain fetch + JSON | securequ |
|
|
59
|
+
| --------------------------------------------- | -------------------- | ---------------------- |
|
|
60
|
+
| Hide request structure from casual inspection | ✗ | ✓ (encrypted envelope) |
|
|
61
|
+
| Automatic compression + binary serialization | Partial (manual) | ✓ built‑in |
|
|
62
|
+
| Short‑lived opaque request token | Custom work | ✓ baked in |
|
|
63
|
+
| Client lifecycle hooks | Manual wiring | ✓ hooks API |
|
|
64
|
+
| Validated chunked uploads + progress | Manual / library mix | ✓ integrated |
|
|
65
|
+
|
|
66
|
+
Use it when you want an extra (opaque) layer plus structured uploads without re‑inventing crypto + binary packing. If HTTPS + standard auth covers all your needs and you prefer transparency, you may not need this.
|
|
67
|
+
|
|
68
|
+
## Core Concepts (Abstracted)
|
|
69
|
+
|
|
70
|
+
| Concept | Summary |
|
|
71
|
+
| ------------------ | --------------------------------------------------------------------------------------- |
|
|
72
|
+
| Pre‑shared secret | Static value per allowed origin (server‑side registration) |
|
|
73
|
+
| Handshake | Lightweight exchange producing a short‑lived opaque token (auto refreshed) |
|
|
74
|
+
| Encrypted envelope | Bodies (and in production, query params) serialized → compressed → encrypted |
|
|
75
|
+
| Development mode | Skips encryption for non‑handshake application requests to aid debugging |
|
|
76
|
+
| Hooks | Extensibility points for request & upload lifecycle events |
|
|
77
|
+
| Chunked upload | Deterministic splitting + metadata negotiation + ordered transfer + completion callback |
|
|
78
|
+
|
|
79
|
+
## Security (Summary)
|
|
80
|
+
|
|
81
|
+
Implemented (High Level):
|
|
82
|
+
- Symmetric encryption with authenticated integrity (AEAD style)
|
|
83
|
+
- Short token lifetime, minimizing replay viability
|
|
84
|
+
- Payload and (production) query obfuscation
|
|
85
|
+
- Optional file‑type validation via first‑chunk signature scanning
|
|
86
|
+
|
|
87
|
+
Operator Responsibilities:
|
|
88
|
+
- Enforce HTTPS and standard secure headers
|
|
89
|
+
- Generate long, random client secrets and rotate periodically
|
|
90
|
+
- Layer proper authentication/authorization (sessions, tokens, etc.)
|
|
91
|
+
- Validate and sanitize business data in handlers
|
|
92
|
+
|
|
93
|
+
Out of Scope:
|
|
94
|
+
- Forward secrecy / per‑message key rotation
|
|
95
|
+
- Fine‑grained end‑user authentication
|
|
96
|
+
- True streaming (payloads are presently buffered)
|
|
97
|
+
- Built‑in rate limiting / abuse controls
|
|
98
|
+
|
|
99
|
+
## Performance Snapshot
|
|
100
|
+
|
|
101
|
+
- Compression + binary encoding reduce large structured bodies vs raw JSON
|
|
102
|
+
- Overhead is minimal for medium/large payloads; for tiny payloads (< 200B) you may prefer plain requests
|
|
103
|
+
- Chunk size is adaptive (you can override) to balance memory and progress smoothness
|
|
104
|
+
- File type detection (if enabled) inspects only the first chunk
|
|
105
|
+
|
|
106
|
+
## Install
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
npm install securequ
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Peer/runtime deps are installed automatically (libsodium, fflate, msgpackr, path-to-regexp, xanfetch).
|
|
113
|
+
|
|
114
|
+
## Minimal Server (Express)
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import express from 'express';
|
|
118
|
+
import { SecurequServer } from 'securequ';
|
|
119
|
+
|
|
120
|
+
const api = new SecurequServer({
|
|
121
|
+
mode: 'production',
|
|
122
|
+
basepath: '/api',
|
|
123
|
+
clients: [{ origin: 'https://app.example.com' | "*", secret: process.env.APP_CLIENT_SECRET! }],
|
|
124
|
+
upload: {
|
|
125
|
+
chunk: async (chunk, meta) => { /* store chunk */ return true; },
|
|
126
|
+
complete: async (meta) => { /* stitch & persist */ return `/files/${meta.fileid}`; },
|
|
127
|
+
failed: async (meta) => boolean
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
api.post('/echo', ({ body }) => { throw { ok: true, body }; });
|
|
132
|
+
|
|
133
|
+
const app = express();
|
|
134
|
+
app.use('/api/*', express.raw({ type: 'application/octet-stream', limit: '20mb' }), async (req, res) => {
|
|
135
|
+
const r = await api.listen(req.originalUrl, {
|
|
136
|
+
body: req.body,
|
|
137
|
+
headers: req.headers,
|
|
138
|
+
}, req);
|
|
139
|
+
res.status(r.status).end(r.content);
|
|
140
|
+
});
|
|
141
|
+
app.listen(4000);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Minimal Client
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import { SecurequClient } from 'securequ';
|
|
148
|
+
|
|
149
|
+
const client = new SecurequClient({
|
|
150
|
+
url: 'https://api.example.com/api',
|
|
151
|
+
secret: '<client-secret>'
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Simple request
|
|
155
|
+
const res = await client.post('echo', { body: { hello: 'world' } });
|
|
156
|
+
console.log(res);
|
|
157
|
+
|
|
158
|
+
// File upload with progress
|
|
159
|
+
async function uploadFile(file: File) {
|
|
160
|
+
const result = await client.upload(file, p => console.log('progress %', p));
|
|
161
|
+
console.log(result);
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Client Hooks (Selected)
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
hooks: {
|
|
169
|
+
beforeRequest: (path, init) => init,
|
|
170
|
+
afterResponse: (resp) => {},
|
|
171
|
+
beforeUpload: (file, fileId) => file,
|
|
172
|
+
afterUpload: (response, file) => {},
|
|
173
|
+
beforeUploadChunk: (chunk, idx, total) => {},
|
|
174
|
+
afterUploadChunk: (resp, idx, total) => {},
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## API Surface (High Level)
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
// Client
|
|
182
|
+
client.get(path, init?)
|
|
183
|
+
client.post(path, init?)
|
|
184
|
+
client.put(path, init?)
|
|
185
|
+
client.delete(path, init?)
|
|
186
|
+
client.upload(file, onProgress?)
|
|
187
|
+
|
|
188
|
+
// Server
|
|
189
|
+
server.get(path, handler)
|
|
190
|
+
server.post(path, handler)
|
|
191
|
+
server.put(path, handler)
|
|
192
|
+
server.delete(path, handler)
|
|
193
|
+
server.listen(url, listenerInfo)
|
|
194
|
+
|
|
195
|
+
// Utilities (optional direct use)
|
|
196
|
+
import { crypto, compresor } from 'securequ';
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Server Response Model
|
|
200
|
+
|
|
201
|
+
Handlers conclude by `throw`ing:
|
|
202
|
+
- Plain object / primitive → serialized (dev) or encrypted (prod) with 200 status
|
|
203
|
+
- `Response` instance → its status/body is used (still wrapped if necessary)
|
|
204
|
+
- `Error` → message returned with a not‑found style status (configurable via customization if you wrap upstream)
|
|
205
|
+
|
|
206
|
+
This pattern deliberately short‑circuits route evaluation and keeps handler code linear.
|
|
207
|
+
|
|
208
|
+
## File Upload Overview
|
|
209
|
+
|
|
210
|
+
- Client sends metadata first
|
|
211
|
+
- Server accepts and tracks state
|
|
212
|
+
- Client streams fixed‑size chunks sequentially
|
|
213
|
+
- Final chunk triggers assembly + returned path / identifier
|
|
214
|
+
- A failure notification allows cleanup
|
|
215
|
+
|
|
216
|
+
## Configuration (Essentials)
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
// Server
|
|
220
|
+
new SecurequServer({
|
|
221
|
+
mode: 'production' | 'development',
|
|
222
|
+
basepath: '/api',
|
|
223
|
+
clients: [{ origin, secret }],
|
|
224
|
+
upload?: { maxFilesize?, checkFileType?, chunk(), complete(), failed? },
|
|
225
|
+
accept?: (info: HandlerInfo, metadata?: Metadata) => boolean | Promise<boolean>
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Client
|
|
229
|
+
new SecurequClient({
|
|
230
|
+
url: 'https://host/api',
|
|
231
|
+
secret: '<pre-shared>',
|
|
232
|
+
chunkSize?: number,
|
|
233
|
+
hooks?: { ... }
|
|
234
|
+
});
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Error Semantics
|
|
238
|
+
|
|
239
|
+
- Success: `success: true`, `data` contains decrypted payload
|
|
240
|
+
- Expired token is auto‑recovered (one retry) by re-handshaking
|
|
241
|
+
- Server thrown `Error` surfaces message (wrapped) to client
|
|
242
|
+
|
|
243
|
+
## Performance Guidance
|
|
244
|
+
|
|
245
|
+
- Use production mode for real benchmarking (encryption path active)
|
|
246
|
+
- Keep secrets long & random (>= 32 chars)
|
|
247
|
+
- Tune `chunkSize` only if you need very granular progress events
|
|
248
|
+
|
|
249
|
+
## Troubleshooting
|
|
250
|
+
|
|
251
|
+
| Symptom | Possible Cause | Suggested Fix |
|
|
252
|
+
| -------------------------------- | ------------------------------------ | ----------------------------------------------------------------- |
|
|
253
|
+
| `Signeture expired` loops | Clock skew or token window too short | Ensure system clocks are synced; minimize artificial delays |
|
|
254
|
+
| Always 404 / Not found | Route not registered before `listen` | Register handlers before attaching middleware |
|
|
255
|
+
| Plain text visible in production | App running in development mode | Set `mode: 'production'` in server config |
|
|
256
|
+
| Upload stops mid‑way | Page navigation / tab close | Use `beforeunload` UI warning or resume strategy (future roadmap) |
|
|
257
|
+
| File type rejected | Magic bytes not recognized | Disable `checkFileType` or extend scanner if needed |
|
|
258
|
+
| High CPU for tiny payloads | Compression/encryption overhead | Bypass securequ for very small trivial requests |
|
|
259
|
+
|
|
260
|
+
If an issue isn’t listed: enable development mode locally to inspect raw (unencrypted) bodies for debugging, then switch back.
|
|
261
|
+
|
|
262
|
+
## FAQ
|
|
263
|
+
|
|
264
|
+
**Does this replace TLS?**
|
|
265
|
+
No. It layers *on top* of TLS.
|
|
266
|
+
|
|
267
|
+
**Can I plug into another HTTP framework?**
|
|
268
|
+
Yes—adapt the raw body + headers and call `server.listen()`.
|
|
269
|
+
|
|
270
|
+
**How do I add auth?**
|
|
271
|
+
Put your auth tokens/data *inside* the encrypted body or add middleware before calling `listen`.
|
|
272
|
+
|
|
273
|
+
**TypeScript support?**
|
|
274
|
+
Fully typed. Route handlers get a typed `info` object; client responses are typed with a generic shape (`SecurequClientResponse`).
|
|
275
|
+
|
|
276
|
+
**Can I inspect payloads in production?**
|
|
277
|
+
Not without decrypting. Use development mode locally when introspection is needed.
|
|
278
|
+
|
|
279
|
+
**Is there resume upload support?**
|
|
280
|
+
Not yet; planned. You can implement partial detection using hooks + server state.
|
|
281
|
+
|
|
282
|
+
**How big can files be?**
|
|
283
|
+
Limited by your configured `maxFilesize` (KB) and infrastructure memory / timeout constraints.
|
|
284
|
+
|
|
285
|
+
## Versioning & Stability
|
|
286
|
+
|
|
287
|
+
The project follows semantic versioning principles as features mature. Prior to a formal `1.x` stability declaration, minor releases may introduce carefully documented adjustments. Pin exact versions in sensitive production environments.
|
|
288
|
+
|
|
289
|
+
## Contributing
|
|
290
|
+
|
|
291
|
+
1. Fork & create a feature branch
|
|
292
|
+
2. Add or adjust tests where behavior changes
|
|
293
|
+
3. Ensure TypeScript builds without errors
|
|
294
|
+
4. Open a PR with a concise rationale
|
|
295
|
+
|
|
296
|
+
Please avoid including sensitive implementation details in public issue titles (describe at a high level instead).
|
|
297
|
+
|
|
298
|
+
## Security Reporting
|
|
299
|
+
|
|
300
|
+
If you believe you have discovered a vulnerability, please refrain from opening a public issue. Instead contact the maintainer privately (add a SECURITY.md for formal process if publishing broadly). Provide a minimal, reproducible scenario.
|
|
301
|
+
|
|
302
|
+
## Disclaimer
|
|
303
|
+
|
|
304
|
+
securequ provides an additional obfuscation + encryption layer. It is not a substitute for robust authentication, authorization, or transport security practices. Combine with TLS, secret rotation, and standard security controls.
|
|
305
|
+
|
|
306
|
+
## License
|
|
307
|
+
|
|
308
|
+
No license file included. Add one (e.g., MIT) before publishing publicly.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
Issues & contributions welcome.
|
|
312
|
+
|