Skip to content

Create vulnerable.js#2

Open
shwetarkadam wants to merge 1 commit intomainfrom
feature/demo7
Open

Create vulnerable.js#2
shwetarkadam wants to merge 1 commit intomainfrom
feature/demo7

Conversation

@shwetarkadam
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread vulnerable.js
const serializedData = req.body.data;
try {
const deserializedData = JSON.parse(serializedData);
res.send(`Deserialized data: ${deserializedData}`);

Check failure

Code scanning / CodeQL

Reflected cross-site scripting

Cross-site scripting vulnerability due to a [user-provided value](1).
Comment thread vulnerable.js
// Cross-Site Scripting (XSS)
app.get('/greet', (req, res) => {
const name = req.query.name;
res.send(`<h1>Hello, ${name}</h1>`);

Check failure

Code scanning / CodeQL

Reflected cross-site scripting

Cross-site scripting vulnerability due to a [user-provided value](1).
Comment thread vulnerable.js
// Insecure JWT Handling
app.post('/login', (req, res) => {
const user = { id: 1, username: req.body.username };
const token = jwt.sign(user, 'secretkey'); // Weak secret

Check failure

Code scanning / CodeQL

Hard-coded credentials

The hard-coded value "secretkey" is used as [jwt key](1).
Comment thread vulnerable.js
Comment on lines +35 to +44
app.get('/read-file', (req, res) => {
const filename = req.query.filename;
fs.readFile(`/var/data/${filename}`, 'utf8', (err, data) => {
if (err) {
res.status(500).send('File read error');
return;
}
res.send(`File content: ${data}`);
});
});

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [a file system access](1), but is not rate-limited.
Comment thread vulnerable.js
// Unsafe File Operations
app.get('/read-file', (req, res) => {
const filename = req.query.filename;
fs.readFile(`/var/data/${filename}`, 'utf8', (err, data) => {

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression

This path depends on a [user-provided value](1).
Comment thread vulnerable.js
app.post('/execute', (req, res) => {
const code = req.body.code;
try {
const result = vm.runInNewContext(code, {});

Check failure

Code scanning / CodeQL

Code injection

This code execution depends on a [user-provided value](1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants