@nathapp/nestjs-storage 2.1.5 → 3.0.0-rc.4
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/README.md +129 -9
- package/dist/module/storage.module.js.map +1 -1
- package/dist/providers/azure-blob-storage.d.ts +22 -0
- package/dist/providers/azure-blob-storage.js +169 -0
- package/dist/providers/azure-blob-storage.js.map +1 -0
- package/dist/providers/base-storage.d.ts +3 -5
- package/dist/providers/base-storage.js +4 -1
- package/dist/providers/base-storage.js.map +1 -1
- package/dist/providers/dropbox-storage.d.ts +3 -5
- package/dist/providers/dropbox-storage.js +84 -151
- package/dist/providers/dropbox-storage.js.map +1 -1
- package/dist/providers/gcs-storage.d.ts +22 -0
- package/dist/providers/gcs-storage.js +132 -0
- package/dist/providers/gcs-storage.js.map +1 -0
- package/dist/providers/gdrive-storage.d.ts +3 -5
- package/dist/providers/gdrive-storage.js +109 -192
- package/dist/providers/gdrive-storage.js.map +1 -1
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/local-storage.d.ts +5 -6
- package/dist/providers/local-storage.js +68 -128
- package/dist/providers/local-storage.js.map +1 -1
- package/dist/providers/oss-storage.d.ts +1 -1
- package/dist/providers/oss-storage.js +10 -4
- package/dist/providers/oss-storage.js.map +1 -1
- package/dist/providers/provider-factory.js +8 -0
- package/dist/providers/provider-factory.js.map +1 -1
- package/dist/providers/s3-base-storage.d.ts +7 -10
- package/dist/providers/s3-base-storage.js +50 -95
- package/dist/providers/s3-base-storage.js.map +1 -1
- package/dist/service/storage-service.d.ts +3 -0
- package/dist/service/storage-service.js +25 -4
- package/dist/service/storage-service.js.map +1 -1
- package/dist/types/capabilities.d.ts +15 -0
- package/dist/types/capabilities.js +3 -0
- package/dist/types/capabilities.js.map +1 -0
- package/dist/types/clients.d.ts +216 -0
- package/dist/types/clients.js +3 -0
- package/dist/types/clients.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/options.d.ts +28 -2
- package/dist/types/options.js +2 -0
- package/dist/types/options.js.map +1 -1
- package/dist/types/storage.d.ts +7 -2
- package/dist/util/imageUtils.js +9 -3
- package/dist/util/imageUtils.js.map +1 -1
- package/docs/20260215-fix-plan-storage.md +66 -0
- package/docs/20260215-implementation-report.md +33 -0
- package/docs/20260215-plan-storage-providers.md +207 -0
- package/docs/20260215-review-storage-postfix.md +278 -0
- package/docs/20260215-review-storage.md +284 -0
- package/docs/20260216-plan-storage-a-minus.md +41 -0
- package/docs/20260216-review-storage-postfix2.md +102 -0
- package/docs/gdrive-security.md +222 -0
- package/docs/provider-capabilities.md +448 -0
- package/package.json +8 -3
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Plan: Standardize Providers + Add Azure Blob & GCS
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-02-15
|
|
4
|
+
**Package:** @nathapp/nestjs-storage
|
|
5
|
+
**Branch:** feat/monorepo-enterprise-upgrade
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Goals
|
|
10
|
+
|
|
11
|
+
1. Add **Azure Blob Storage** and **Google Cloud Storage (GCS)** providers
|
|
12
|
+
2. Standardize all provider implementations for consistency
|
|
13
|
+
3. Document S3-compatible providers (MinIO, DigitalOcean Spaces, Backblaze B2, Wasabi, Tencent COS)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Phase 1: Provider Standardization (refactor existing)
|
|
18
|
+
|
|
19
|
+
### 1A. Optional Capability Interfaces
|
|
20
|
+
|
|
21
|
+
Replace "Method not implemented" throws with capability detection:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// lib/types/capabilities.ts
|
|
25
|
+
|
|
26
|
+
/** Provider supports generating signed URLs for direct access */
|
|
27
|
+
export interface ISignedUrlCapable {
|
|
28
|
+
getSignedUrl(fileId: string, expires?: number): Promise<string>;
|
|
29
|
+
getObjectUrl(fileId: string): Promise<string>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Provider supports client-side upload credentials (e.g., STS tokens, presigned POST) */
|
|
33
|
+
export interface IClientUploadCapable {
|
|
34
|
+
getClientUploadCredential(option: ClientCredentialOptions): Promise<any>;
|
|
35
|
+
resolveClientUploadCallback(payload: ClientUploadCallbackPayload, options?: ClientUploadCallbackOptions): Promise<ClientUploadCallbackResult>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Provider supports server-side image preprocessing */
|
|
39
|
+
export interface IImageProcessingCapable {
|
|
40
|
+
preprocessImage(sourceFileId: string, targetFileId: string, options: PreprocessImageOptions): Promise<PreprocessImageResult>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Provider supports partial/range reads */
|
|
44
|
+
export interface IStreamCapable {
|
|
45
|
+
streamFile(fileId: string, range: string): Promise<PartialStream>;
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 1B. Update BaseStorage
|
|
50
|
+
|
|
51
|
+
- Remove `getClientUploadCredential`, `resolveClientUploadCallback`, `preprocessImage` from abstract class
|
|
52
|
+
- Keep core CRUD + `getSignedUrl` as abstract (all cloud providers support this)
|
|
53
|
+
- Make `streamFile` optional via `IStreamCapable`
|
|
54
|
+
- Add static capability check:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
static supportsSignedUrl(storage: BaseStorage): storage is BaseStorage & ISignedUrlCapable {
|
|
58
|
+
return 'getSignedUrl' in storage && typeof storage.getSignedUrl === 'function';
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 1C. Standardize Async Patterns
|
|
63
|
+
|
|
64
|
+
All providers MUST use `async/await` — no `new Promise` wrappers around callback-style APIs.
|
|
65
|
+
|
|
66
|
+
**LocalStorage:** Replace `fs.mkdir(path, callback)` → `fs.promises.mkdir(path)`
|
|
67
|
+
**S3BaseStorage:** Replace `new Promise((resolve, reject) => { ... .promise().then() })` → `async/await`
|
|
68
|
+
**GDriveStorage:** Same treatment
|
|
69
|
+
**DropboxStorage:** Already mostly async, clean up remaining Promise wrappers
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Phase 2: New Providers
|
|
74
|
+
|
|
75
|
+
### 2A. Azure Blob Storage
|
|
76
|
+
|
|
77
|
+
**SDK:** `@azure/storage-blob` (peer dependency, optional)
|
|
78
|
+
**Auth:** Connection string or `DefaultAzureCredential`
|
|
79
|
+
**Options:**
|
|
80
|
+
```typescript
|
|
81
|
+
export type AzureBlobOptions = {
|
|
82
|
+
connectionString?: string;
|
|
83
|
+
accountName?: string;
|
|
84
|
+
accountKey?: string;
|
|
85
|
+
containerName: string;
|
|
86
|
+
sasToken?: string;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type AzureBlobStorageOption = {
|
|
90
|
+
provider: Provider.AZURE_BLOB;
|
|
91
|
+
options: AzureBlobOptions;
|
|
92
|
+
};
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Implementation notes:**
|
|
96
|
+
- Uses `BlobServiceClient` → `ContainerClient` → `BlockBlobClient`
|
|
97
|
+
- `readFile` → `download()` returns `ReadableStream`
|
|
98
|
+
- `putFile` → `upload(data, data.length)`
|
|
99
|
+
- `getSignedUrl` → `generateBlobSASQueryParameters`
|
|
100
|
+
- Supports range requests natively via `download(offset, count)`
|
|
101
|
+
- No native folder concept (uses prefix-based listing like S3)
|
|
102
|
+
|
|
103
|
+
### 2B. Google Cloud Storage (GCS)
|
|
104
|
+
|
|
105
|
+
**SDK:** `@google-cloud/storage` (peer dependency, optional)
|
|
106
|
+
**Auth:** Service account JSON or Application Default Credentials
|
|
107
|
+
**Options:**
|
|
108
|
+
```typescript
|
|
109
|
+
export type GCSOptions = {
|
|
110
|
+
projectId?: string;
|
|
111
|
+
keyFilename?: string;
|
|
112
|
+
credentials?: { client_email: string; private_key: string };
|
|
113
|
+
bucketName: string;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type GCSStorageOption = {
|
|
117
|
+
provider: Provider.GCS;
|
|
118
|
+
options: GCSOptions;
|
|
119
|
+
};
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Implementation notes:**
|
|
123
|
+
- Uses `Storage` → `Bucket` → `File`
|
|
124
|
+
- `readFile` → `file.createReadStream()`
|
|
125
|
+
- `putFile` → `file.save(data)`
|
|
126
|
+
- `getSignedUrl` → `file.getSignedUrl({ action: 'read', expires })`
|
|
127
|
+
- Supports range requests via `createReadStream({ start, end })`
|
|
128
|
+
- Folder-like structure via prefix listing (same as S3)
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Phase 3: S3-Compatible Documentation
|
|
133
|
+
|
|
134
|
+
Add README section documenting that these work via existing S3 provider with custom endpoint:
|
|
135
|
+
|
|
136
|
+
| Provider | Endpoint Pattern | Notes |
|
|
137
|
+
|----------|-----------------|-------|
|
|
138
|
+
| MinIO | `http://minio:9000` | Self-hosted, set `s3ForcePathStyle: true` |
|
|
139
|
+
| DigitalOcean Spaces | `https://{region}.digitaloceanspaces.com` | Region: nyc3, sfo3, etc. |
|
|
140
|
+
| Backblaze B2 | `https://s3.{region}.backblazeb2.com` | Region: us-west-002, etc. |
|
|
141
|
+
| Wasabi | `https://s3.{region}.wasabisys.com` | No egress fees |
|
|
142
|
+
| Tencent COS | `https://cos.{region}.myqcloud.com` | Region: ap-guangzhou, etc. |
|
|
143
|
+
| Supabase Storage | `https://{project}.supabase.co/storage/v1/s3` | Needs S3 protocol enabled |
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Phase 4: Provider Capability Matrix (README)
|
|
148
|
+
|
|
149
|
+
| Capability | Local | NFS | S3/R2 | OSS | Azure | GCS | GDrive | Dropbox |
|
|
150
|
+
|-----------|-------|-----|-------|-----|-------|-----|--------|---------|
|
|
151
|
+
| putFile | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
152
|
+
| readFile | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
153
|
+
| getSignedUrl | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
154
|
+
| streamFile | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ |
|
|
155
|
+
| clientUpload | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
156
|
+
| preprocessImage | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Files to Create/Modify
|
|
161
|
+
|
|
162
|
+
### New Files
|
|
163
|
+
- `lib/types/capabilities.ts` — capability interfaces
|
|
164
|
+
- `lib/providers/azure-blob-storage.ts` — Azure Blob provider
|
|
165
|
+
- `lib/providers/gcs-storage.ts` — GCS provider
|
|
166
|
+
- `test/azure-blob-storage.spec.ts` — Azure unit tests (mocked SDK)
|
|
167
|
+
- `test/gcs-storage.spec.ts` — GCS unit tests (mocked SDK)
|
|
168
|
+
|
|
169
|
+
### Modified Files
|
|
170
|
+
- `lib/types/options.ts` — Add `AZURE_BLOB`, `GCS` to Provider enum + option types
|
|
171
|
+
- `lib/types/storage.ts` — Re-export capabilities
|
|
172
|
+
- `lib/providers/base-storage.ts` — Remove optional methods from abstract, add capability checks
|
|
173
|
+
- `lib/providers/provider-factory.ts` — Add new providers to switch
|
|
174
|
+
- `lib/providers/index.ts` — Export new providers
|
|
175
|
+
- `lib/providers/local-storage.ts` — Refactor to `fs.promises`
|
|
176
|
+
- `lib/providers/s3-base-storage.ts` — Refactor to async/await
|
|
177
|
+
- `lib/providers/gdrive-storage.ts` — Refactor to async/await
|
|
178
|
+
- `lib/providers/dropbox-storage.ts` — Clean up promise wrappers
|
|
179
|
+
- `package.json` — Add `@azure/storage-blob` + `@google-cloud/storage` as optional peer deps
|
|
180
|
+
- `README.md` — S3-compatible docs + capability matrix
|
|
181
|
+
|
|
182
|
+
### NOT Modified (out of scope)
|
|
183
|
+
- `nfs-storage.ts` — Remains a stub (different architecture, JWT-based)
|
|
184
|
+
- `oss-storage.ts` — Already mostly async, complex callback validation logic stays as-is
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Breaking Changes
|
|
189
|
+
|
|
190
|
+
⚠️ **BaseStorage abstract class changes:**
|
|
191
|
+
- `getClientUploadCredential`, `resolveClientUploadCallback`, `preprocessImage` removed from abstract
|
|
192
|
+
- Moved to optional interfaces (`IClientUploadCapable`, `IImageProcessingCapable`)
|
|
193
|
+
- Existing code calling these methods directly will still work (they exist on OSS which is the only implementer)
|
|
194
|
+
- Code using `BaseStorage` type to call these methods will need to use capability check
|
|
195
|
+
|
|
196
|
+
**This is a breaking change for TypeScript consumers who reference BaseStorage type directly.**
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Execution
|
|
201
|
+
|
|
202
|
+
Single sub-agent with phases:
|
|
203
|
+
1. Phase 1: Capability interfaces + BaseStorage refactor + async standardization
|
|
204
|
+
2. Phase 2: Azure Blob + GCS providers with tests
|
|
205
|
+
3. Phase 3: Package.json, exports, factory, README
|
|
206
|
+
|
|
207
|
+
Estimated: ~15-20 files touched, moderate complexity.
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# Post-Fix Review: @nathapp/nestjs-storage
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-02-15
|
|
4
|
+
**Reviewer:** Subrina (AI)
|
|
5
|
+
**Version:** 2.1.5
|
|
6
|
+
**Baseline Review:** 20260215-review-storage.md (Grade C, 65/100)
|
|
7
|
+
**Tests:** 5 suites, 10 tests passing
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Overall Grade: B (78/100)
|
|
12
|
+
|
|
13
|
+
**Previous:** C (65/100)
|
|
14
|
+
**Change:** +13 points
|
|
15
|
+
|
|
16
|
+
All P0 (blocker) items have been successfully resolved. The package now has proper path traversal protection, fixed the AWS credential exposure risk, corrected the S3 stream type mismatch, and added error handlers to prevent resource leaks. A new security test suite was added to prevent regression. However, several P1/P2 items remain unaddressed including anti-pattern promise wrappers, excessive `any` types, image format validation, and documentation gaps.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## P0 Items: Status ✅ ALL RESOLVED
|
|
21
|
+
|
|
22
|
+
### ✅ SEC-1: Path Traversal Vulnerability - FIXED
|
|
23
|
+
**Original Risk:** CRITICAL - Attackers could read/write files outside storage root
|
|
24
|
+
**Fix Applied:**
|
|
25
|
+
```typescript
|
|
26
|
+
// lib/providers/local-storage.ts:23
|
|
27
|
+
private validatePath(filePath: string): string {
|
|
28
|
+
const absolutePath = path.resolve(this.root, filePath);
|
|
29
|
+
if (!absolutePath.startsWith(this.root)) {
|
|
30
|
+
throw new Error(`Path traversal detected: ${filePath}`);
|
|
31
|
+
}
|
|
32
|
+
return absolutePath;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
**Verification:**
|
|
36
|
+
- Method called in all file operations (createFolder, deleteFileOrFolder, getFileOrFolder, putFile, readFile, etc.)
|
|
37
|
+
- New test suite added: `test/local-storage-security.spec.ts` with 3 test cases
|
|
38
|
+
- Tests cover basic traversal (`../../../../etc/passwd`) and null byte attacks
|
|
39
|
+
- **Status:** ✅ RESOLVED
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
### ✅ SEC-2: Unused AWS Import - FIXED
|
|
44
|
+
**Original Risk:** CRITICAL - Forced aws-sdk load, potential credential leakage
|
|
45
|
+
**Fix Applied:** Removed `import { bool } from "aws-sdk/clients/signer";` from `lib/types/storage.ts`
|
|
46
|
+
**Verification:** File no longer imports aws-sdk
|
|
47
|
+
**Status:** ✅ RESOLVED
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
### ✅ BUG-1: S3 readFile Return Type - FIXED
|
|
52
|
+
**Original Risk:** CRITICAL - Type mismatch causing runtime crashes
|
|
53
|
+
**Fix Applied:**
|
|
54
|
+
```typescript
|
|
55
|
+
// lib/providers/s3-base-storage.ts:97
|
|
56
|
+
readFile(fileId: string) {
|
|
57
|
+
return new Promise<NodeJS.ReadableStream>((resolve, reject) => {
|
|
58
|
+
this.storage.getObject({...}).promise()
|
|
59
|
+
.then((data) => {
|
|
60
|
+
if (data.Body instanceof Readable) {
|
|
61
|
+
data.Body.on('error', reject);
|
|
62
|
+
resolve(data.Body);
|
|
63
|
+
} else if (Buffer.isBuffer(data.Body) || typeof data.Body === 'string') {
|
|
64
|
+
resolve(Readable.from(data.Body));
|
|
65
|
+
} else {
|
|
66
|
+
resolve(Readable.from(data.Body as any));
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
.catch(reject);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
**Verification:**
|
|
74
|
+
- Handles Readable stream, Buffer, and string types
|
|
75
|
+
- Proper error listener attached
|
|
76
|
+
- Converts Buffer/string to Readable stream via `Readable.from()`
|
|
77
|
+
- **Status:** ✅ RESOLVED
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
### ✅ MEM-1: Stream Error Handlers - FIXED
|
|
82
|
+
**Original Risk:** CRITICAL - File descriptor leaks in long-running services
|
|
83
|
+
**Fix Applied:**
|
|
84
|
+
```typescript
|
|
85
|
+
// lib/providers/local-storage.ts:104
|
|
86
|
+
const stream = fs.createReadStream(absolutePath);
|
|
87
|
+
stream.on('error', reject); // <-- Added
|
|
88
|
+
resolve(stream);
|
|
89
|
+
```
|
|
90
|
+
**Verification:**
|
|
91
|
+
- Error listener added in `readFile()` before resolving
|
|
92
|
+
- Error listener added in `streamFile()` for range requests
|
|
93
|
+
- S3 readFile also includes error handling (see BUG-1 fix)
|
|
94
|
+
- **Status:** ✅ RESOLVED
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## P1 Items: Status ❌ NOT ADDRESSED
|
|
99
|
+
|
|
100
|
+
### ❌ PERF-1: Anti-Pattern Promise Wrappers - NOT FIXED
|
|
101
|
+
**Status:** NOT ADDRESSED
|
|
102
|
+
**Locations:** LocalStorage (all methods), S3BaseStorage (some methods), OssStorage, GDriveStorage
|
|
103
|
+
|
|
104
|
+
LocalStorage still uses `new Promise((resolve, reject) => { fs.mkdir(...) })` pattern instead of `fs.promises.mkdir()`. This adds overhead and complexity.
|
|
105
|
+
|
|
106
|
+
**Example (unchanged):**
|
|
107
|
+
```typescript
|
|
108
|
+
// lib/providers/local-storage.ts:28
|
|
109
|
+
createFolder(filePath: string) {
|
|
110
|
+
// ... validatePath logic ...
|
|
111
|
+
return new Promise<IFile>((resolve, reject) => {
|
|
112
|
+
fs.mkdir(absolutePath, (err) => { // Should use fs.promises.mkdir
|
|
113
|
+
if (err) { reject(err); }
|
|
114
|
+
else { this.getFileOrFolder(filePath).then(resolve).catch(reject); }
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Impact on Grade:** Code quality and maintainability penalty
|
|
121
|
+
**Recommendation:** Refactor LocalStorage to use `fs.promises` API in 3.0.0
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
### ❌ TYPE-1: Excessive use of `any` - NOT FIXED
|
|
126
|
+
**Status:** NOT ADDRESSED
|
|
127
|
+
**Locations:**
|
|
128
|
+
- `s3-base-storage.ts:12` - `private readonly storage: any`
|
|
129
|
+
- `oss-storage.ts:13` - `private readonly storage: any`
|
|
130
|
+
- `gdrive-storage.ts:9` - `private readonly drive: any`
|
|
131
|
+
|
|
132
|
+
**Impact:** No compile-time type checking for storage provider operations
|
|
133
|
+
**Recommendation:** Define minimal interfaces or use proper SDK types
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### ❌ BUG-2: compressImageBuffer Unsafe Format - NOT FIXED
|
|
138
|
+
**Status:** NOT ADDRESSED
|
|
139
|
+
**Location:** `lib/util/imageUtils.ts:49`
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
const { format } = meta // No validation
|
|
143
|
+
return image.toFormat(format, config[format]).toBuffer(); // config[format] could be undefined
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Risk:** Unsupported formats (svg, pdf, heic) cause silent failures or security bypass
|
|
147
|
+
**Recommendation:** Whitelist allowed formats before calling `toFormat()`
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
### ❌ ENH-1: Unsupported Methods Documentation - NOT FIXED
|
|
152
|
+
**Status:** NOT ADDRESSED
|
|
153
|
+
|
|
154
|
+
Methods throwing "Not Implemented" lack JSDoc `@throws` annotations or README capability matrix:
|
|
155
|
+
- `S3BaseStorage`: `getClientUploadCredential`, `resolveClientUploadCallback`, `preprocessImage`
|
|
156
|
+
- `LocalStorage`: Same 3 + `getObjectUrl`, `getSignedUrl`
|
|
157
|
+
|
|
158
|
+
**Impact:** Developers discover limitations only at runtime
|
|
159
|
+
**Recommendation:** Add JSDoc `@throws` + create provider capability matrix in README
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## P2 Items: Status ❌ NOT ADDRESSED
|
|
164
|
+
|
|
165
|
+
### ❌ SEC-3: OSS Signature Timing Attack - NOT FIXED
|
|
166
|
+
**Location:** `lib/providers/oss-storage.ts:323`
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
private validateSignature(pubKey: string, signature: Buffer, toSignByte: string): boolean {
|
|
170
|
+
const verify = crypto.createVerify("RSA-MD5");
|
|
171
|
+
verify.update(toSignByte);
|
|
172
|
+
return verify.verify(pubKey, signature); // Direct boolean comparison
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**Risk:** Timing attack possible (low probability but present)
|
|
177
|
+
**Recommendation:** Document as low-risk or add constant-time comparison wrapper
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
### ❌ BUG-3: Image Resize Logic - NOT FIXED
|
|
182
|
+
**Location:** `lib/util/imageUtils.ts:43`
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
if ((width && meta.width && meta.width > width) || (height && meta.height && meta.height > height)) {
|
|
186
|
+
image.resize(width, height, resizeOptions);
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**Risk:** Calling `resize(100, null)` when only width is set may cause unexpected behavior
|
|
191
|
+
**Recommendation:** Separate width/height logic or validate both are set
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
### ❌ BUG-4: GDrive refreshToken Security - NOT FIXED
|
|
196
|
+
**Location:** `lib/providers/gdrive-storage.ts:16`
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
auth.setCredentials({
|
|
200
|
+
refresh_token: options.options.refreshToken, // No warning about logging/exposure
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Risk:** Refresh token could be logged in error messages
|
|
205
|
+
**Recommendation:** Add JSDoc warning about secure storage requirements
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
### ❌ STYLE-2: Commented Test Code - NOT FIXED
|
|
210
|
+
**Location:** `test/util/imageUtils.spec.ts`
|
|
211
|
+
|
|
212
|
+
All functional image compression tests remain commented out with message "Skip Test, apline image not support".
|
|
213
|
+
|
|
214
|
+
**Impact:** Zero confidence in image compression functionality
|
|
215
|
+
**Recommendation:** Fix Alpine compatibility or use different test base image
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## P3 Items: Status ⚠️ UNKNOWN
|
|
220
|
+
|
|
221
|
+
### ⚠️ ENH-2: TypeScript Strict Mode
|
|
222
|
+
**Status:** UNKNOWN (requires checking parent config)
|
|
223
|
+
`tsconfig.json` extends `@nathapp/typescript-config/base.json` - need to verify if strict mode is enabled there.
|
|
224
|
+
|
|
225
|
+
### ❌ ENH-3: Missing JSDoc - NOT FIXED
|
|
226
|
+
Public APIs in `BaseStorage`, `StorageService`, and utility functions still lack JSDoc comments.
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Updated Grading Rubric
|
|
231
|
+
|
|
232
|
+
| Dimension | Before | After | Change | Rationale |
|
|
233
|
+
|:---|:---|:---|:---|:---|
|
|
234
|
+
| **Security** | 10/20 | 17/20 | +7 | Path traversal fixed, AWS import removed; SEC-3, BUG-4 remain |
|
|
235
|
+
| **Reliability** | 11/20 | 17/20 | +6 | Stream errors fixed, type mismatch resolved; promise anti-patterns remain |
|
|
236
|
+
| **API Design** | 14/20 | 14/20 | 0 | ENH-1 not addressed |
|
|
237
|
+
| **Code Quality** | 12/20 | 12/20 | 0 | PERF-1, STYLE-2 not addressed |
|
|
238
|
+
| **Best Practices** | 18/20 | 18/20 | 0 | No change |
|
|
239
|
+
|
|
240
|
+
**Total Score: 78/100 (B)**
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Test Coverage Update
|
|
245
|
+
|
|
246
|
+
**Before:** 4 test suites (mostly DI registration, image tests commented)
|
|
247
|
+
**After:** 5 test suites, 10 tests passing
|
|
248
|
+
- **New:** `local-storage-security.spec.ts` (3 tests for SEC-1)
|
|
249
|
+
- **Unchanged:** `imageUtils.spec.ts` still has commented tests
|
|
250
|
+
|
|
251
|
+
**Functional Coverage:** Still <15% (image compression untested, cloud provider operations untested)
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Recommendations
|
|
256
|
+
|
|
257
|
+
### ✅ Production Ready
|
|
258
|
+
With all P0 items resolved, the package is now **safe for production use** in its current form. The critical security vulnerabilities and memory leaks have been eliminated.
|
|
259
|
+
|
|
260
|
+
### 🔶 Before 3.0.0 Release
|
|
261
|
+
1. **P1 Priority:** Address TYPE-1 (define storage provider interfaces)
|
|
262
|
+
2. **P1 Priority:** Fix BUG-2 (image format validation)
|
|
263
|
+
3. **P1 Priority:** Document ENH-1 (unsupported methods matrix)
|
|
264
|
+
4. **Code Quality:** Consider refactoring LocalStorage to `fs.promises` (PERF-1)
|
|
265
|
+
|
|
266
|
+
### 📋 Post-3.0.0 Polish
|
|
267
|
+
- Enable/verify strict TypeScript mode (ENH-2)
|
|
268
|
+
- Fix Alpine image compatibility for image compression tests (STYLE-2)
|
|
269
|
+
- Add JSDoc to all public APIs (ENH-3)
|
|
270
|
+
- Consider constant-time comparison for OSS signature (SEC-3)
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Summary
|
|
275
|
+
|
|
276
|
+
**4/4 P0 items fixed** - excellent turnaround. The package moved from "significant security issues" to "production-ready with known limitations." The addition of security tests demonstrates good defensive programming. Grade improved from C to B (+13 points).
|
|
277
|
+
|
|
278
|
+
**Next action:** Address P1 items (TYPE-1, BUG-2, ENH-1) to push grade to B+ or A- for 3.0.0 release.
|