Skip to content

Commit 3a005b8

Browse files
committed
skip xss
1 parent bf41a1e commit 3a005b8

File tree

6 files changed

+22
-4
lines changed

6 files changed

+22
-4
lines changed

src/__tests__/routes.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,12 @@ describe('API Routes', () => {
335335

336336
it('should handle invalid query parameters gracefully', async () => {
337337
const res = await request(app).get('/v1/technologies?invalid=parameter');
338-
expect(res.statusCode).toEqual(400);
339-
expect(res.body).toHaveProperty('errors');
340-
expect(res.body.errors[0]).toHaveProperty('error');
341-
expect(res.body.errors[0].error).toContain('Unsupported parameters: ');
338+
expect(res.statusCode).toEqual(200);
339+
expect(Array.isArray(res.body)).toBe(true);
340+
341+
//expect(res.body).toHaveProperty('errors');
342+
//expect(res.body.errors[0]).toHaveProperty('error');
343+
//expect(res.body.errors[0].error).toContain('Unsupported parameters: ');
342344
});
343345
});
344346

src/controllers/categoriesController.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { executeQuery, validateArrayParameter } from '../utils/controllerHelpers
66
*/
77
const listCategories = async (req, res) => {
88
const queryBuilder = async (params) => {
9+
/*
910
// Validate parameters
1011
const supportedParams = ['category', 'onlyname', 'fields'];
1112
const providedParams = Object.keys(params);
@@ -16,6 +17,7 @@ const listCategories = async (req, res) => {
1617
error.statusCode = 400;
1718
throw error;
1819
}
20+
*/
1921

2022
const isOnlyNames = params.onlyname || typeof params.onlyname === 'string';
2123
const hasCustomFields = params.fields && !isOnlyNames;

src/controllers/reportController.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const createReportController = (reportType) => {
4949
try {
5050
const params = req.query;
5151

52+
/*
5253
// Validate supported parameters
5354
const supportedParams = ['technology', 'geo', 'rank', 'start', 'end'];
5455
const providedParams = Object.keys(params);
@@ -59,6 +60,7 @@ const createReportController = (reportType) => {
5960
error.statusCode = 400;
6061
throw error;
6162
}
63+
*/
6264

6365
// Validate required parameters using shared utility
6466
const errors = validateRequiredParams(params, [

src/controllers/technologiesController.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { executeQuery, validateTechnologyArray, validateArrayParameter, FIRESTOR
66
*/
77
const listTechnologies = async (req, res) => {
88
const queryBuilder = async (params) => {
9+
/*
910
// Validate parameters
1011
const supportedParams = ['technology', 'category', 'onlyname', 'fields'];
1112
const providedParams = Object.keys(params);
@@ -16,6 +17,7 @@ const listTechnologies = async (req, res) => {
1617
error.statusCode = 400;
1718
throw error;
1819
}
20+
*/
1921

2022
const isOnlyNames = params.onlyname || typeof params.onlyname === 'string';
2123
const hasCustomFields = params.fields && !isOnlyNames;

src/controllers/versionsController.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { executeQuery, validateTechnologyArray, FIRESTORE_IN_LIMIT } from '../ut
66
*/
77
const listVersions = async (req, res) => {
88
const queryBuilder = async (params) => {
9+
/*
910
// Validate parameters
1011
const supportedParams = ['version', 'technology', 'category', 'onlyname', 'fields'];
1112
const providedParams = Object.keys(params);
@@ -16,6 +17,7 @@ const listVersions = async (req, res) => {
1617
error.statusCode = 400;
1718
throw error;
1819
}
20+
*/
1921

2022
let query = firestore.collection('versions');
2123

src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ const handleRequest = async (req, res) => {
105105
return;
106106
}
107107

108+
// Validate URL to skip XSS attacks
109+
const unsafe = /onerror|onload|javascript:/i;
110+
if (unsafe.test(req.url)) {
111+
res.statusCode = 400
112+
res.end(JSON.stringify({ error: 'Invalid input' }));
113+
return;
114+
}
115+
108116
// Parse URL
109117
const parsedUrl = url.parse(req.url, true);
110118
const pathname = parsedUrl.pathname;

0 commit comments

Comments
 (0)