path-sanitizer 3.0.0 → 3.0.1
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/.github/workflows/ci.yml +12 -9
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -1
- package/package.json +26 -25
- package/tsconfig.json +14 -14
package/.github/workflows/ci.yml
CHANGED
|
@@ -13,20 +13,23 @@ jobs:
|
|
|
13
13
|
runs-on: ubuntu-latest
|
|
14
14
|
|
|
15
15
|
steps:
|
|
16
|
-
- name: Checkout
|
|
17
|
-
uses: actions/checkout@
|
|
16
|
+
- name: Checkout
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
18
|
|
|
19
|
-
-
|
|
20
|
-
|
|
19
|
+
- uses: pnpm/action-setup@v4
|
|
20
|
+
name: Install pnpm
|
|
21
21
|
with:
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
version: 9
|
|
23
|
+
run_install: false
|
|
24
24
|
|
|
25
|
-
- name: Install
|
|
26
|
-
|
|
25
|
+
- name: Install Node.js
|
|
26
|
+
uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: 22
|
|
29
|
+
cache: 'pnpm'
|
|
27
30
|
|
|
28
31
|
- name: Install dependencies
|
|
29
32
|
run: pnpm install
|
|
30
33
|
|
|
31
34
|
- name: Run tests
|
|
32
|
-
run: pnpm test
|
|
35
|
+
run: pnpm test
|
package/dist/index.d.ts
CHANGED
|
@@ -27,5 +27,8 @@ interface SanitizeOptionsComplete {
|
|
|
27
27
|
notAllowedRegEx: RegExp;
|
|
28
28
|
}
|
|
29
29
|
export declare const DEFAULT_OPTIONS: SanitizeOptionsComplete;
|
|
30
|
+
/**
|
|
31
|
+
* Sanitizes a portion of a path to avoid Path Traversal
|
|
32
|
+
*/
|
|
30
33
|
export default function sanitize(pathstr: string, options?: SanitizeOptions): string;
|
|
31
34
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,9 @@ exports.DEFAULT_OPTIONS = {
|
|
|
21
21
|
parentDirectoryRegEx: /[\/\\]\.\.[\/\\]/g,
|
|
22
22
|
notAllowedRegEx: /:|\$|!|'|"|@|\+|`|\||=/g
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Sanitizes a portion of a path to avoid Path Traversal
|
|
26
|
+
*/
|
|
24
27
|
function sanitize(pathstr, options = exports.DEFAULT_OPTIONS) {
|
|
25
28
|
if (!options)
|
|
26
29
|
options = exports.DEFAULT_OPTIONS;
|
|
@@ -71,5 +74,7 @@ function sanitize(pathstr, options = exports.DEFAULT_OPTIONS) {
|
|
|
71
74
|
sanitizedPath = sanitizedPath.replace(/[\\]/g, '/');
|
|
72
75
|
// Replace double (back)slashes with a single slash
|
|
73
76
|
sanitizedPath = sanitizedPath.replace(/[\/\\]+/g, '/');
|
|
74
|
-
|
|
77
|
+
// Make sure out is not "."
|
|
78
|
+
sanitizedPath = sanitizedPath.trim() === '.' ? '' : sanitizedPath;
|
|
79
|
+
return sanitizedPath.trim();
|
|
75
80
|
}
|
package/package.json
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "path-sanitizer",
|
|
3
|
-
"version": "3.0.
|
|
4
|
-
"description": "A simple lightweight npm package for sanitizing paths to prevent Path Traversal",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "vitest"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "path-sanitizer",
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"description": "A simple lightweight npm package for sanitizing paths to prevent Path Traversal",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "vitest",
|
|
8
|
+
"build": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "Cabra (https://github.com/cabraviva)",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/cabraviva/path-sanitizer.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/cabraviva/path-sanitizer/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/cabraviva/path-sanitizer#readme",
|
|
21
|
+
"types": "dist/index.d.ts",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^22.9.3",
|
|
24
|
+
"typescript": "^5.7.2",
|
|
25
|
+
"vitest": "^2.1.5"
|
|
26
|
+
}
|
|
26
27
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNEXT",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"strict": true
|
|
8
|
-
},
|
|
9
|
-
"include": [
|
|
10
|
-
"lib/*.ts"
|
|
11
|
-
],
|
|
12
|
-
"exclude": [
|
|
13
|
-
"lib/*.test.ts"
|
|
14
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNEXT",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"strict": true
|
|
8
|
+
},
|
|
9
|
+
"include": [
|
|
10
|
+
"lib/*.ts"
|
|
11
|
+
],
|
|
12
|
+
"exclude": [
|
|
13
|
+
"lib/*.test.ts"
|
|
14
|
+
]
|
|
15
15
|
}
|