Skip to content

Commit d433526

Browse files
committed
fix: normalize tgz path
1 parent 9aec6a8 commit d433526

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

config.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"version": "< 1.0.0"
3434
},
3535
{
36-
"policy": "deny",
37-
"dateRange": ["2010-01-01T00:00:00.000Z", "2025-01-01T00:00:00.000Z"]
36+
"policy": "allow",
37+
"_dateRange": ["2010-01-01T00:00:00.000Z", "2025-01-01T00:00:00.000Z"]
3838
}
3939
]
4040
}

src/main/js/app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const createApp = (cfg) => {
2121
[
2222
'*',
2323
[
24-
/^\/(((@[a-z0-9\-]+)(%2f|\/))?[a-z0-9\-]+)\/-\/[a-z0-9\-]+-(\d+\.\d+\.\d+(?:-.+)?)\.tgz$/,
24+
/^\/(((@[a-z0-9\-]+)(%2f|\/))?[a-z0-9\-]+)\/-\/[a-z0-9\-]+-(\d+\.\d+\.\d+(-[+\-.a-z0-9]+)?)\.tgz$/,
2525
['name', null, 'org', null, 'version']
2626
],
2727
firewall(registry, rules)

src/main/js/http/client.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import http from 'node:http'
22
import https from 'node:https'
33
import {parse} from 'node:url'
44

5-
import { makeDeferred } from '../util.js'
5+
import {makeDeferred, normalizePath} from '../util.js'
66

77
export const request = async (opts) => {
88
const {url, method = 'GET', postData, pipe, followRedirects, timeout = 30_000} = opts
@@ -14,7 +14,7 @@ export const request = async (opts) => {
1414
hostname,
1515
port = isSecure ? 443 : 80,
1616
lib = isSecure ? https : http
17-
} = parse(url)
17+
} = parse(normalizePath(url))
1818

1919
const {promise, resolve, reject} = makeDeferred()
2020

src/main/js/mwares/proxy.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ export const proxy = (registry) => async (req, res, next) => {
66
}
77

88
const url = `${registry}${req.url}`
9-
109
await request({ url, method: req.method, pipe: {req, res}, followRedirects: true})
1110
}

src/test/js/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const app = createApp([{
1111
],
1212
firewall: {
1313
registry: 'https://registry.npmmirror.com',
14+
base: '/registry',
1415
rules: [
1516
{
1617
"policy": "deny",
@@ -37,17 +38,17 @@ await app.start()
3738
],
3839
[
3940
'404 if not found',
40-
{ url: 'http://localhost:3001/not-found/path/on/remote', method: 'GET'},
41+
{ url: 'http://localhost:3001/registry/not-found/path/on/remote', method: 'GET'},
4142
{ statusCode: 404 }
4243
],
4344
[
4445
'gets tarball if allowed',
45-
{ url: 'http://localhost:3001/@antongolub/git-root/-/git-root-1.5.6.tgz', method: 'GET'},
46+
{ url: 'http://localhost:3001/registry/@antongolub/git-root/-/git-root-1.5.6.tgz', method: 'GET'},
4647
{ hash: 'uMs0P/SZUnoc+oF6E0VVPSnkXphOfg1GXRl+wnx/tElmLNPtNCuh2n7EVbSJU5hv73q96YK04bBVRQmS2p2Cjw==' }
4748
],
4849
[
4950
'reads packument',
50-
{ url: 'http://localhost:3001/colors', method: 'GET'},
51+
{ url: 'http://localhost:3001/registry/colors', method: 'GET'},
5152
{ statusCode: 200 }
5253
],
5354
].forEach(([name, {url, method}, expected]) => {

0 commit comments

Comments
 (0)