2017-04-19 21:15:28 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const assert = require('assert');
|
2013-12-19 16:11:54 +01:00
|
|
|
|
|
|
|
module.exports = function() {
|
2017-04-19 21:15:28 +02:00
|
|
|
let server = process.server;
|
2013-12-29 07:40:47 +01:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
describe('Security', function() {
|
2015-04-11 19:11:04 +02:00
|
|
|
before(function() {
|
2017-04-19 21:15:28 +02:00
|
|
|
return server.add_package('testpkg-sec');
|
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
it('bad pkg #1', function() {
|
2015-04-11 19:11:04 +02:00
|
|
|
return server.get_package('package.json')
|
|
|
|
.status(403)
|
2017-04-19 21:15:28 +02:00
|
|
|
.body_error(/invalid package/);
|
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
it('bad pkg #2', function() {
|
2015-04-11 19:11:04 +02:00
|
|
|
return server.get_package('__proto__')
|
|
|
|
.status(403)
|
2017-04-19 21:15:28 +02:00
|
|
|
.body_error(/invalid package/);
|
|
|
|
});
|
2015-03-28 19:25:53 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
it('__proto__, connect stuff', function() {
|
|
|
|
return server.request({uri: '/testpkg-sec?__proto__=1'})
|
|
|
|
.then(function(body) {
|
2015-04-11 19:11:04 +02:00
|
|
|
// test for NOT outputting stack trace
|
2017-04-19 21:15:28 +02:00
|
|
|
assert(!body || typeof(body) === 'object' || body.indexOf('node_modules') === -1);
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
// test for NOT crashing
|
2017-04-19 21:15:28 +02:00
|
|
|
return server.request({uri: '/testpkg-sec'}).status(200);
|
|
|
|
});
|
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
it('do not return package.json as an attachment', function() {
|
|
|
|
return server.request({uri: '/testpkg-sec/-/package.json'})
|
2015-04-11 19:11:04 +02:00
|
|
|
.status(403)
|
2017-04-19 21:15:28 +02:00
|
|
|
.body_error(/invalid filename/);
|
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
it('silly things - reading #1', function() {
|
|
|
|
return server.request({uri: '/testpkg-sec/-/../../../../../../../../etc/passwd'})
|
|
|
|
.status(404);
|
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
it('silly things - reading #2', function() {
|
|
|
|
return server.request({uri: '/testpkg-sec/-/%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd'})
|
2015-04-11 19:11:04 +02:00
|
|
|
.status(403)
|
2017-04-19 21:15:28 +02:00
|
|
|
.body_error(/invalid filename/);
|
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
it('silly things - writing #1', function() {
|
2015-04-11 19:11:04 +02:00
|
|
|
return server.put_tarball('testpkg-sec', 'package.json', '{}')
|
|
|
|
.status(403)
|
2017-04-19 21:15:28 +02:00
|
|
|
.body_error(/invalid filename/);
|
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
it('silly things - writing #3', function() {
|
2015-04-11 19:11:04 +02:00
|
|
|
return server.put_tarball('testpkg-sec', 'node_modules', '{}')
|
|
|
|
.status(403)
|
2017-04-19 21:15:28 +02:00
|
|
|
.body_error(/invalid filename/);
|
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
it('silly things - writing #4', function() {
|
2015-04-11 19:11:04 +02:00
|
|
|
return server.put_tarball('testpkg-sec', '../testpkg.tgz', '{}')
|
|
|
|
.status(403)
|
2017-04-19 21:15:28 +02:00
|
|
|
.body_error(/invalid filename/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2013-12-19 16:11:54 +01:00
|
|
|
|