2022-01-09 20:31:26 +01:00
|
|
|
import _ from 'lodash';
|
2013-12-19 19:11:54 +04:00
|
|
|
|
2022-01-09 20:51:50 +01:00
|
|
|
import { HTTP_STATUS } from '../../../src/lib/constants';
|
|
|
|
|
2021-03-14 08:42:46 +01:00
|
|
|
export default function (server) {
|
2018-06-23 09:18:31 +02:00
|
|
|
describe('should test security on endpoints', () => {
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2017-06-28 22:56:02 +02:00
|
|
|
return server.addPackage('testpkg-sec');
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 19:11:54 +04:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch bad pkg #1', () => {
|
2021-03-14 08:42:46 +01:00
|
|
|
return server
|
|
|
|
.getPackage('__proto__')
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid package/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 19:11:54 +04:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch bad pkg #2', () => {
|
2021-03-14 08:42:46 +01:00
|
|
|
return server
|
|
|
|
.getPackage('__proto__')
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid package/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2015-03-28 21:25:53 +03:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should do not fails on __proto__, connect stuff', () => {
|
2021-03-14 08:42:46 +01:00
|
|
|
return server.request({ uri: '/testpkg-sec?__proto__=1' }).then(function (body) {
|
|
|
|
// test for NOT outputting stack trace
|
|
|
|
expect(_.isNil(body) || _.isObject(body) || body.indexOf('node_modules')).toBeTruthy();
|
2013-12-19 19:11:54 +04:00
|
|
|
|
2021-03-14 08:42:46 +01:00
|
|
|
// test for NOT crashing
|
|
|
|
return server.request({ uri: '/testpkg-sec' }).status(HTTP_STATUS.OK);
|
|
|
|
});
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 19:11:54 +04:00
|
|
|
|
2018-12-06 08:34:42 +01:00
|
|
|
test('should fails and do not return __proto__ as an attachment', () => {
|
2021-03-14 08:42:46 +01:00
|
|
|
return server
|
|
|
|
.request({ uri: '/testpkg-sec/-/__proto__' })
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid filename/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 19:11:54 +04:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch silly things - reading #1', () => {
|
2023-01-18 22:49:28 +01:00
|
|
|
return server
|
|
|
|
.request({ uri: '/testpkg-sec/-/../../../../../../../../etc/passwd' })
|
|
|
|
.status(HTTP_STATUS.NOT_FOUND);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 19:11:54 +04:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch silly things - reading #2', () => {
|
2021-03-14 08:42:46 +01:00
|
|
|
return server
|
|
|
|
.request({
|
2022-01-09 20:51:50 +01:00
|
|
|
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',
|
2021-03-14 08:42:46 +01:00
|
|
|
})
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid filename/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 19:11:54 +04:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch silly things - writing #1', () => {
|
2021-03-14 08:42:46 +01:00
|
|
|
return server
|
|
|
|
.putTarball('testpkg-sec', '__proto__', '{}')
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid filename/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 19:11:54 +04:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch silly things - writing #3', () => {
|
2021-03-14 08:42:46 +01:00
|
|
|
return server
|
|
|
|
.putTarball('testpkg-sec', 'node_modules', '{}')
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid filename/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 19:11:54 +04:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch silly things - writing #4', () => {
|
2021-03-14 08:42:46 +01:00
|
|
|
return server
|
|
|
|
.putTarball('testpkg-sec', '../testpkg.tgz', '{}')
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid filename/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
|
|
|
});
|
2017-12-02 11:20:27 +01:00
|
|
|
}
|