koa-files 3.0.6 → 3.0.7
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/cjs/Service.cjs +5 -5
- package/cjs/index.cjs +1 -1
- package/cjs/utils/fs.cjs +1 -1
- package/cjs/utils/hash.cjs +1 -1
- package/cjs/utils/http.cjs +5 -5
- package/cjs/utils/path.cjs +1 -1
- package/esm/Service.js +5 -5
- package/esm/index.js +1 -1
- package/esm/utils/fs.js +1 -1
- package/esm/utils/hash.js +1 -1
- package/esm/utils/http.js +5 -5
- package/esm/utils/path.js +1 -1
- package/package.json +2 -2
- package/types/utils/http.d.ts +4 -4
package/cjs/Service.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.0.
|
|
4
|
+
* @version 3.0.7
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -196,13 +196,13 @@ class Service {
|
|
|
196
196
|
if (context.method !== 'GET' && context.method !== 'HEAD') {
|
|
197
197
|
return false;
|
|
198
198
|
}
|
|
199
|
-
// Get
|
|
199
|
+
// Get pathname of file.
|
|
200
200
|
const pathname = http.decodeURI(context.path);
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (path$2 === -1 || path$2.includes('\0')) {
|
|
201
|
+
// Pathname decode failed or includes null byte(s).
|
|
202
|
+
if (pathname === -1 || pathname.includes('\0')) {
|
|
204
203
|
return context.throw(400);
|
|
205
204
|
}
|
|
205
|
+
const path$2 = path.unixify(path$1.join(root, pathname));
|
|
206
206
|
// Malicious path (403).
|
|
207
207
|
if (path.isOutRoot(path$2, root)) {
|
|
208
208
|
return false;
|
package/cjs/index.cjs
CHANGED
package/cjs/utils/fs.cjs
CHANGED
package/cjs/utils/hash.cjs
CHANGED
package/cjs/utils/http.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.0.
|
|
4
|
+
* @version 3.0.7
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -108,7 +108,7 @@ function decodeURI(URI) {
|
|
|
108
108
|
/**
|
|
109
109
|
* @function isConditionalGET
|
|
110
110
|
* @description Check if request is conditional GET.
|
|
111
|
-
* @param context
|
|
111
|
+
* @param context The koa context.
|
|
112
112
|
*/
|
|
113
113
|
function isConditionalGET(context) {
|
|
114
114
|
const { request } = context;
|
|
@@ -122,7 +122,7 @@ function isConditionalGET(context) {
|
|
|
122
122
|
/**
|
|
123
123
|
* @function isPreconditionFailure
|
|
124
124
|
* @description Check if request precondition failure.
|
|
125
|
-
* @param context
|
|
125
|
+
* @param context The koa context.
|
|
126
126
|
*/
|
|
127
127
|
function isPreconditionFailure({ request, response }) {
|
|
128
128
|
// If-Match.
|
|
@@ -147,8 +147,8 @@ function isPreconditionFailure({ request, response }) {
|
|
|
147
147
|
/**
|
|
148
148
|
* @function parseRanges
|
|
149
149
|
* @description Parse ranges.
|
|
150
|
-
* @param context
|
|
151
|
-
* @param stats
|
|
150
|
+
* @param context The koa context.
|
|
151
|
+
* @param stats The file stats.
|
|
152
152
|
*/
|
|
153
153
|
function parseRanges(context, stats) {
|
|
154
154
|
const { size } = stats;
|
package/cjs/utils/path.cjs
CHANGED
package/esm/Service.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.0.
|
|
4
|
+
* @version 3.0.7
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -187,13 +187,13 @@ class Service {
|
|
|
187
187
|
if (context.method !== 'GET' && context.method !== 'HEAD') {
|
|
188
188
|
return false;
|
|
189
189
|
}
|
|
190
|
-
// Get
|
|
190
|
+
// Get pathname of file.
|
|
191
191
|
const pathname = decodeURI(context.path);
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (path === -1 || path.includes('\0')) {
|
|
192
|
+
// Pathname decode failed or includes null byte(s).
|
|
193
|
+
if (pathname === -1 || pathname.includes('\0')) {
|
|
195
194
|
return context.throw(400);
|
|
196
195
|
}
|
|
196
|
+
const path = unixify(join(root, pathname));
|
|
197
197
|
// Malicious path (403).
|
|
198
198
|
if (isOutRoot(path, root)) {
|
|
199
199
|
return false;
|
package/esm/index.js
CHANGED
package/esm/utils/fs.js
CHANGED
package/esm/utils/hash.js
CHANGED
package/esm/utils/http.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.0.
|
|
4
|
+
* @version 3.0.7
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -100,7 +100,7 @@ function decodeURI(URI) {
|
|
|
100
100
|
/**
|
|
101
101
|
* @function isConditionalGET
|
|
102
102
|
* @description Check if request is conditional GET.
|
|
103
|
-
* @param context
|
|
103
|
+
* @param context The koa context.
|
|
104
104
|
*/
|
|
105
105
|
function isConditionalGET(context) {
|
|
106
106
|
const { request } = context;
|
|
@@ -114,7 +114,7 @@ function isConditionalGET(context) {
|
|
|
114
114
|
/**
|
|
115
115
|
* @function isPreconditionFailure
|
|
116
116
|
* @description Check if request precondition failure.
|
|
117
|
-
* @param context
|
|
117
|
+
* @param context The koa context.
|
|
118
118
|
*/
|
|
119
119
|
function isPreconditionFailure({ request, response }) {
|
|
120
120
|
// If-Match.
|
|
@@ -139,8 +139,8 @@ function isPreconditionFailure({ request, response }) {
|
|
|
139
139
|
/**
|
|
140
140
|
* @function parseRanges
|
|
141
141
|
* @description Parse ranges.
|
|
142
|
-
* @param context
|
|
143
|
-
* @param stats
|
|
142
|
+
* @param context The koa context.
|
|
143
|
+
* @param stats The file stats.
|
|
144
144
|
*/
|
|
145
145
|
function parseRanges(context, stats) {
|
|
146
146
|
const { size } = stats;
|
package/esm/utils/path.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koa-files",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"description": "A static files serving middleware for koa.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "cjs/index.cjs",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@types/koa": "^2.15.0",
|
|
67
67
|
"@types/range-parser": "^1.2.7",
|
|
68
68
|
"koa": "^2.15.3",
|
|
69
|
-
"magic-string": "^0.30.
|
|
69
|
+
"magic-string": "^0.30.12",
|
|
70
70
|
"prettier": "^3.3.3",
|
|
71
71
|
"rimraf": "^6.0.1",
|
|
72
72
|
"rollup": "^4.24.0",
|
package/types/utils/http.d.ts
CHANGED
|
@@ -19,20 +19,20 @@ export declare function decodeURI(URI: string): string | -1;
|
|
|
19
19
|
/**
|
|
20
20
|
* @function isConditionalGET
|
|
21
21
|
* @description Check if request is conditional GET.
|
|
22
|
-
* @param context
|
|
22
|
+
* @param context The koa context.
|
|
23
23
|
*/
|
|
24
24
|
export declare function isConditionalGET(context: Context): boolean;
|
|
25
25
|
/**
|
|
26
26
|
* @function isPreconditionFailure
|
|
27
27
|
* @description Check if request precondition failure.
|
|
28
|
-
* @param context
|
|
28
|
+
* @param context The koa context.
|
|
29
29
|
*/
|
|
30
30
|
export declare function isPreconditionFailure({ request, response }: Context): boolean;
|
|
31
31
|
/**
|
|
32
32
|
* @function parseRanges
|
|
33
33
|
* @description Parse ranges.
|
|
34
|
-
* @param context
|
|
35
|
-
* @param stats
|
|
34
|
+
* @param context The koa context.
|
|
35
|
+
* @param stats The file stats.
|
|
36
36
|
*/
|
|
37
37
|
export declare function parseRanges(context: Context, stats: Stats): Ranges;
|
|
38
38
|
export {};
|