-
Notifications
You must be signed in to change notification settings - Fork 212
New branch sast inline #81
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| const express = require('express'); | ||
| const mongoose = require('mongoose'); | ||
|
|
||
| const app = express(); | ||
| const port = 3000; | ||
|
|
||
| // Connect to MongoDB | ||
| mongoose.connect('mongodb://localhost:27017/users_db', { | ||
| useNewUrlParser: true, | ||
| useUnifiedTopology: true | ||
| }); | ||
|
|
||
| const User = mongoose.model('User', new mongoose.Schema({ username: String, password: String })); | ||
|
|
||
| // ⚠️ SAST ISSUE: NoSQL Injection vulnerability ⚠️ | ||
| app.get('/user', async (req, res) => { | ||
| const username = req.query.username; // User-controlled input | ||
|
|
||
| // 🚨 UNSAFE: Directly passing user input into MongoDB query 🚨 | ||
| const user = await User.findOne({ username: username }); | ||
|
|
||
| if (!user) { | ||
| return res.status(404).send('User not found'); | ||
| } | ||
|
|
||
| res.json(user); | ||
| }); | ||
|
|
||
| app.listen(port, () => { | ||
| console.log(`Server running on http://localhost:${port}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| const express = require('express'); | ||
| const mongoose = require('mongoose'); | ||
|
|
||
| const app = express(); | ||
| const port = 3000; | ||
|
|
||
| // Connect to MongoDB | ||
| mongoose.connect('mongodb://localhost:27017/users_db', { | ||
| useNewUrlParser: true, | ||
| useUnifiedTopology: true | ||
| }); | ||
|
|
||
| const User = mongoose.model('User', new mongoose.Schema({ username: String, password: String })); | ||
|
|
||
| // ⚠️ SAST ISSUE: NoSQL Injection vulnerability ⚠️ | ||
| app.get('/user', async (req, res) => { | ||
| const username = req.query.username; // User-controlled input | ||
|
|
||
| // 🚨 UNSAFE: Directly passing user input into MongoDB query 🚨 | ||
| const user = await User.findOne({ username: username }); | ||
|
|
||
| if (!user) { | ||
| return res.status(404).send('User not found'); | ||
| } | ||
|
|
||
| res.json(user); | ||
| }); | ||
|
|
||
| app.listen(port, () => { | ||
| console.log(`Server running on http://localhost:${port}`); | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,31 @@ | ||||||
| const express = require('express'); | ||||||
| const mongoose = require('mongoose'); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Codacy found a critical ErrorProne issue: Require statement not part of import statement. The issue described by the ESLint linter indicates that the code is using CommonJS syntax ( To fix this issue, you can change the
Suggested change
This comment was generated by an experimental AI tool. |
||||||
|
|
||||||
| const app = express(); | ||||||
| const port = 3000; | ||||||
|
|
||||||
| // Connect to MongoDB | ||||||
| mongoose.connect('mongodb://localhost:27017/users_db', { | ||||||
| useNewUrlParser: true, | ||||||
| useUnifiedTopology: true | ||||||
| }); | ||||||
|
|
||||||
| const User = mongoose.model('User', new mongoose.Schema({ username: String, password: String })); | ||||||
|
|
||||||
| // ⚠️ SAST ISSUE: NoSQL Injection vulnerability ⚠️ | ||||||
| app.get('/user', async (req, res) => { | ||||||
| const username = req.query.username; // User-controlled input | ||||||
|
|
||||||
| // 🚨 UNSAFE: Directly passing user input into MongoDB query 🚨 | ||||||
| const user = await User.findOne({ username: username }); | ||||||
|
Check warning on line 20 in testPR.js
|
||||||
|
|
||||||
| if (!user) { | ||||||
| return res.status(404).send('User not found'); | ||||||
| } | ||||||
|
|
||||||
| res.json(user); | ||||||
| }); | ||||||
|
|
||||||
| app.listen(port, () => { | ||||||
| console.log(`Server running on http://localhost:${port}`); | ||||||
| }); | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Codacy found a critical ErrorProne issue: Require statement not part of import statement.
The issue reported by ESLint indicates that the use of
requireis not in line with modern JavaScript practices, particularly when using ES6 modules. The linter suggests that you should use theimportstatement instead ofrequireto import modules, asimportis part of the ES6 module syntax which is more aligned with the current standards for JavaScript.To resolve this issue, you can change the
requirestatement to animportstatement. Here's the suggested change:This single line change will update the module import to use the ES6 syntax, addressing the ESLint warning. However, please note that if you switch to using
import, you may also need to ensure that your environment supports ES modules or configure your project accordingly (e.g., using Babel or setting"type": "module"in yourpackage.json).This comment was generated by an experimental AI tool.