Skip to content

Commit 6554973

Browse files
authored
feat: allows package.json as package name (#1149)
1 parent 9d3b7ba commit 6554973

File tree

5 files changed

+7
-12
lines changed

5 files changed

+7
-12
lines changed

src/lib/local-storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ class LocalStorage implements IStorage {
409409
_transform.apply(uploadStream, arguments);
410410
};
411411

412-
if (name === pkgFileName || name === '__proto__') {
412+
if (name === '__proto__') {
413413
process.nextTick(() => {
414414
uploadStream.emit('error', ErrorCode.getForbidden());
415415
});

src/lib/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ function validateName(name: string): boolean {
7575
name.charAt(0) === '-' || // "-" is reserved by couchdb
7676
name === 'node_modules' ||
7777
name === '__proto__' ||
78-
name === 'package.json' ||
7978
name === 'favicon.ico'
8079
);
8180
}

test/functional/sanity/security.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function(server) {
99
});
1010

1111
test('should fails on fetch bad pkg #1', () => {
12-
return server.getPackage('package.json')
12+
return server.getPackage('__proto__')
1313
.status(HTTP_STATUS.FORBIDDEN)
1414
.body_error(/invalid package/);
1515
});
@@ -31,8 +31,8 @@ export default function(server) {
3131
});
3232
});
3333

34-
test('should fails and do not return package.json as an attachment', () => {
35-
return server.request({uri: '/testpkg-sec/-/package.json'})
34+
test('should fails and do not return __proto__ as an attachment', () => {
35+
return server.request({uri: '/testpkg-sec/-/__proto__'})
3636
.status(HTTP_STATUS.FORBIDDEN)
3737
.body_error(/invalid filename/);
3838
});
@@ -49,7 +49,7 @@ export default function(server) {
4949
});
5050

5151
test('should fails on fetch silly things - writing #1', () => {
52-
return server.putTarball('testpkg-sec', 'package.json', '{}')
52+
return server.putTarball('testpkg-sec', '__proto__', '{}')
5353
.status(HTTP_STATUS.FORBIDDEN)
5454
.body_error(/invalid filename/);
5555
});

test/unit/api/local-storage.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ describe('LocalStorage', () => {
344344
stream.on('error', (err) => {
345345
expect(err).not.toBeNull();
346346
expect(err.statusCode).toEqual(HTTP_STATUS.CONFLICT);
347-
expect(err.message).toMatch(/this package is already present/);
347+
expect(err.message).toMatch(/this package is already present/);
348348
});
349349
stream.on('success', function(){
350350
expect(spy).toHaveBeenCalled();
@@ -385,7 +385,7 @@ describe('LocalStorage', () => {
385385
});
386386

387387
test('should fails on abort on add a new tarball', (done) => {
388-
const stream = storage.addTarball('package.json', `${pkgName}-fails-add-tarball-1.0.4.tgz`);
388+
const stream = storage.addTarball('__proto__', `${pkgName}-fails-add-tarball-1.0.4.tgz`);
389389
stream.abort();
390390
stream.on('error', function(err) {
391391
expect(err).not.toBeNull();

test/unit/api/utils.spec.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ describe('Utilities', () => {
5959
assert(validate('JSONStream'));
6060
});
6161

62-
test('no package.json', () => {
63-
assert(!validate('package.json'));
64-
});
65-
6662
test('no path seps', () => {
6763
assert(!validate('some/thing'));
6864
assert(!validate('some\\thing'));

0 commit comments

Comments
 (0)