Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh security check #2803

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@types/react": "^16.2.0",
"chalk": "4.1.2",
"classnames": "^2.3.2",
"express": "^4.19.2",
"glob": "^7.2.0",
"inquirer": "^8.2.0",
"jscodeshift": "^0.13.1",
Expand Down
69 changes: 69 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const express = require('express');
const app = express();
const port = 3000;

app.use(express.urlencoded({extended: true}));


app.post('/echo', (req, res) => {
const userInput = req.body.name;

res.send(`Hello, ${userInput}!`);
Fixed Show fixed Hide fixed
});

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});

const http = require('http');
const url = require('url');
const querystring = require('querystring');

const sqlQuery = 'SELECT * FROM users WHERE username = ?';

const command = 'sudo rm -rf /';

const userId = 1;

const message = '<script>alert("hello")</script>';

const formData = {
username: 'admin',
password: 'password123'
};

http.createServer((req, res) => {
const parsedUrl = url.parse(req.url);
let query = '';

if (parsedUrl.query) {
query = querystring.parse(parsedUrl.query);
}

const result = db.query(sqlQuery, [query.username]);

exec(command);

// Vulnerability: Authentication bypass
if (userId === query.user_id) {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.end(`<h1>Welcome, ${query.username}!</h1>`);

Check failure

Code scanning / CodeQL

Reflected cross-site scripting High

Cross-site scripting vulnerability due to a
user-provided value
.
} else {
res.statusCode = 403;
res.setHeader('Content-Type', 'text/plain');
res.end('Forbidden');
}

const escapedMessage = escape(message);
res.write(`<p>${escapedMessage}</p>`);

const form = `<form action="/login" method="post">
<input type="text" name="username">
<input type="password" name="password">
<button type="submit">Login</button>
</form>`;
res.write(form);
}).listen(3000, () => {
console.log('Server started on port 3000');
});
Loading
Loading