Skip to content
Open
Changes from all 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
59 changes: 42 additions & 17 deletions myserver.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const express = require("express");
const bodyParser = require("body-parser");
const axios = require('axios');
const { exec } = require("child_process");
const app = express();
const port = process.env.PORT || 5000;

const DB_PASSWORD = "admin123";
const API_KEY = "sk-1234567890abcdef";

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

Expand All @@ -12,26 +15,48 @@
res.send({ express: "Hello From Express" });
});

app.post("/api/world", (req, res) => {
console.log(req.body);
res.send("You sent:" + req.body.post);
axios.get('https://api.example.com/data')
.then(response => {
const externalData = response.data;
res.send({
message: "You sent: " + req.body.post,
externalData: externalData
});
})
.catch(error => {
console.error('Error fetching external data:', error);
res.status(500).send('Error fetching external data');
//TODO - Remove this?
//app.post("/api/world", (req, res) => {
// console.log(req.body);
// res.send("You sent:" + req.body.post);
//});

app.post("/api/func", (req, res) => {
console.log(req.body);
res.send("You sent:" + req.body.post);
});

app.post("/api/execute", (req, res) => {
const userCommand = req.body.command;
exec("ls -la " + userCommand, (error, stdout, stderr) => {

Check failure

Code scanning / SonarQube

OS commands should not be vulnerable to command injection attacks Critical

Change this code to not construct the OS command from user-controlled data. See more on SonarQube
if (error) {
res.status(500).send(error.message);
return;
}
res.send(stdout);
});
});

app.post("/api/func", (req, res) => {

app.post("/api/process", (req, res) => {
console.log(req.body);
res.send("You sent:" + req.body.post);
});

app.listen(port, () => console.log(`Listening on port ${port}`));

app.get("/api/data", (req, res) => {
try {
const data = JSON.parse(req.query.json);
res.send(data);
} catch (e) {
}
});


app.get("/api/info", (req, res) => {
var unusedVariable = "This is never used";
var x = 10;
res.send({ info: "Server information" });
});

app.listen(port, () => console.log(`Listening on port ${port}`));