Skip to content

Commit 595ea6c

Browse files
committed
files for qhelp
1 parent 57ac944 commit 595ea6c

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const axios = require('axios');
2+
3+
export const handler = async (req, res, next) => {
4+
const { target } = req.body;
5+
6+
try {
7+
// BAD: `target` is controlled by the attacker
8+
const response = await axios.get('https://example.com/current_api/' + target);
9+
10+
// process request response
11+
use(response);
12+
} catch (err) {
13+
// process error
14+
}
15+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const axios = require('axios');
2+
const validator = require('validator');
3+
4+
export const handler = async (req, res, next) => {
5+
const { target } = req.body;
6+
7+
if (!validator.isAlphanumeric(target)) {
8+
return next(new Error('Bad request'));
9+
}
10+
11+
try {
12+
// `target` is validated
13+
const response = await axios.get('https://example.com/current_api/' + target);
14+
15+
// process request response
16+
use(response);
17+
} catch (err) {
18+
// process error
19+
}
20+
};

0 commit comments

Comments
 (0)