koa-classic-server 1.0.6 โ†’ 1.2.0

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.
@@ -0,0 +1,26 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Attach by Process ID",
9
+ "processId": "${command:PickProcess}",
10
+ "request": "attach",
11
+ "skipFiles": [
12
+ "<node_internals>/**"
13
+ ],
14
+ "type": "node"
15
+ },
16
+ {
17
+ "type": "node",
18
+ "request": "launch",
19
+ "name": "Launch Program",
20
+ "skipFiles": [
21
+ "<node_internals>/**"
22
+ ],
23
+ "program": "${workspaceFolder}/index.cjs"
24
+ }
25
+ ]
26
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "name": "Attach by Process ID",
6
+ "processId": "${command:PickProcess}",
7
+ "request": "attach",
8
+ "skipFiles": [
9
+ "<node_internals>/**"
10
+ ],
11
+ "type": "node"
12
+ },
13
+ {
14
+ "type": "node",
15
+ "request": "launch",
16
+ "name": "Launch Program",
17
+ "skipFiles": [
18
+ "<node_internals>/**"
19
+ ],
20
+ "program": "${workspaceFolder}/index.cjs"
21
+ },
22
+ {
23
+ "name": "Debug Jest Tests",
24
+ "type": "node",
25
+ "request": "launch",
26
+ "runtimeExecutable": "node",
27
+ "runtimeArgs": [
28
+ "--inspect-brk",
29
+ "${workspaceFolder}/node_modules/jest/bin/jest.js",
30
+ "--runInBand"
31
+ ],
32
+ "port": 9229,
33
+ "console": "integratedTerminal",
34
+ "internalConsoleOptions": "neverOpen",
35
+ "skipFiles": [
36
+ "<node_internals>/**"
37
+ ]
38
+ }
39
+ ]
40
+ }
41
+
package/CHANGELOG.md ADDED
@@ -0,0 +1,181 @@
1
+ # Changelog
2
+
3
+ All notable changes to koa-classic-server will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.2.0] - 2025-11-17
9
+
10
+ ### ๐ŸŽ‰ SECURITY & BUG FIX RELEASE
11
+
12
+ This release contains **critical security fixes** and important bug fixes. All users should upgrade immediately.
13
+
14
+ ### ๐Ÿ”’ Security Fixes (CRITICAL)
15
+
16
+ #### Fixed Path Traversal Vulnerability
17
+ - **Issue**: Attackers could access files outside the served directory using `../` sequences
18
+ - **Impact**: CRITICAL - Unauthorized file access
19
+ - **Fix**: Added path normalization and validation to ensure all file access stays within `rootDir`
20
+ - **Code**: `index.cjs:106-124`
21
+
22
+ #### Fixed Template Rendering Crash
23
+ - **Issue**: Unhandled errors in template rendering could crash the entire server
24
+ - **Impact**: CRITICAL - Denial of Service
25
+ - **Fix**: Added try-catch around template render calls with proper error handling
26
+ - **Code**: `index.cjs:195-205`
27
+
28
+ ### โœ… Bug Fixes
29
+
30
+ #### Fixed HTTP Status Code 404
31
+ - **Issue**: Missing files returned HTML "Not Found" with HTTP 200 status instead of 404
32
+ - **Impact**: HIGH - Violates HTTP standards, affects SEO, breaks caching
33
+ - **Fix**: Properly set `ctx.status = 404` when resources are not found
34
+ - **Locations**:
35
+ - `index.cjs:130` - File/directory not found
36
+ - `index.cjs:158` - Directory listing disabled
37
+
38
+ #### Fixed Race Condition in File Access
39
+ - **Issue**: Files could be deleted between existence check and reading, causing uncaught errors
40
+ - **Impact**: HIGH - Server crashes on file access errors
41
+ - **Fix**: Added `fs.promises.access()` check before streaming files with error handling
42
+ - **Code**: `index.cjs:208-216`
43
+
44
+ #### Fixed File Extension Extraction
45
+ - **Issue**: Using `split(".")` failed for:
46
+ - Files without extension (`README`)
47
+ - Hidden files (`.gitignore`)
48
+ - Paths with dots (`/folder.backup/file`)
49
+ - **Impact**: HIGH - Template rendering activated incorrectly
50
+ - **Fix**: Use `path.extname()` for robust extension extraction
51
+ - **Code**: `index.cjs:192`
52
+
53
+ #### Fixed Directory Read Errors
54
+ - **Issue**: `fs.readdirSync()` could throw unhandled errors (permissions, deleted directories)
55
+ - **Impact**: MEDIUM - Server crashes on directory access errors
56
+ - **Fix**: Added try-catch with user-friendly error message
57
+ - **Code**: `index.cjs:245-264`
58
+
59
+ #### Fixed Content-Disposition Header
60
+ - **Issue**: Filename in Content-Disposition header was not quoted and included full path
61
+ - **Impact**: MEDIUM - Download issues with special characters in filenames
62
+ - **Fix**:
63
+ - Use only basename (not full path)
64
+ - Quote filename and escape quotes
65
+ - **Code**: `index.cjs:234-239`
66
+
67
+ ### ๐ŸŽจ Improvements
68
+
69
+ #### Added Input Validation
70
+ - Validate `rootDir` is a non-empty string
71
+ - Validate `rootDir` is an absolute path
72
+ - Throw meaningful errors for invalid input
73
+
74
+ #### Added XSS Protection
75
+ - HTML-escape all user-controlled content in directory listings
76
+ - Escapes filenames, paths, and MIME types
77
+ - Prevents XSS attacks through malicious filenames
78
+
79
+ #### Improved Error Messages
80
+ - More descriptive error messages
81
+ - Console logging for debugging
82
+ - Stream error handling
83
+
84
+ #### Code Quality
85
+ - Fixed usage of `Array()` constructor to literal syntax `[]`
86
+ - Better code organization and comments
87
+ - Improved HTML output formatting
88
+
89
+ ### ๐Ÿ“ Added Files
90
+
91
+ - **`__tests__/security.test.js`**: Comprehensive security and bug tests
92
+ - **`DEBUG_REPORT.md`**: Detailed analysis of all bugs and fixes
93
+ - **`DOCUMENTATION.md`**: Complete documentation (1500+ lines)
94
+ - **`CHANGELOG.md`**: This file
95
+
96
+ ### ๐Ÿงช Testing
97
+
98
+ - All 71 tests passing
99
+ - Added security test suite
100
+ - Path traversal tests
101
+ - Template error handling tests
102
+ - Status code validation tests
103
+ - Race condition tests
104
+ - Content-Disposition tests
105
+
106
+ ### ๐Ÿ“ฆ Package Changes
107
+
108
+ - **Version**: `1.1.0` โ†’ `1.2.0`
109
+ - **Description**: Enhanced with security fixes
110
+ - **Keywords**: Added `secure`, `middleware`, `file-server`, `directory-listing`
111
+ - **Scripts**: Added `test:security` command
112
+
113
+ ### โš ๏ธ Breaking Changes
114
+
115
+ **None** - This is a backwards-compatible release. However, behavior changes for security:
116
+
117
+ 1. **404 Status Codes**: Now properly returns 404 instead of 200 for missing resources
118
+ 2. **Path Traversal**: Requests with `../` now return 403 Forbidden instead of allowing access
119
+ 3. **Error Handling**: Template errors return 500 instead of crashing the server
120
+
121
+ These changes fix bugs and security issues. The new behavior is correct and standards-compliant.
122
+
123
+ ### ๐Ÿ”„ Migration Guide
124
+
125
+ No code changes required! Simply update:
126
+
127
+ ```bash
128
+ npm update koa-classic-server
129
+ ```
130
+
131
+ **Recommended**: Verify that:
132
+ 1. `rootDir` is an absolute path (e.g., `__dirname + '/public'`)
133
+ 2. Your error handling expects proper 404/403/500 status codes
134
+ 3. Your tests pass with the new behavior
135
+
136
+ ### ๐Ÿ“Š Statistics
137
+
138
+ - **Lines of code fixed**: ~200
139
+ - **Security vulnerabilities fixed**: 2 critical
140
+ - **Bugs fixed**: 6
141
+ - **Tests added**: 12 security tests
142
+ - **Documentation added**: 2000+ lines
143
+ - **Test coverage**: 71 tests passing
144
+
145
+ ### ๐Ÿ™ Credits
146
+
147
+ - **Author**: Italo Paesano
148
+ - **Security Audit**: Comprehensive code analysis
149
+ - **Testing**: Jest & Supertest
150
+
151
+ ---
152
+
153
+ ## [1.1.0] - Previous Release
154
+
155
+ ### Features
156
+ - Basic static file serving
157
+ - Directory listing
158
+ - Template engine support
159
+ - URL prefixes
160
+ - Reserved URLs
161
+
162
+ ### Known Issues (Fixed in 1.2.0)
163
+ - Path traversal vulnerability โš ๏ธ CRITICAL
164
+ - Missing 404 status codes
165
+ - Unhandled template errors โš ๏ธ CRITICAL
166
+ - Race condition in file access
167
+ - Fragile file extension extraction
168
+ - Missing error handling
169
+
170
+ ---
171
+
172
+ ## Links
173
+
174
+ - [Full Documentation](./DOCUMENTATION.md)
175
+ - [Debug Report](./DEBUG_REPORT.md)
176
+ - [Repository](https://github.com/italopaesano/koa-classic-server)
177
+ - [npm Package](https://www.npmjs.com/package/koa-classic-server)
178
+
179
+ ---
180
+
181
+ **โš ๏ธ Security Notice**: Version 1.2.0 fixes critical vulnerabilities. Update immediately if using 1.1.0 or earlier.