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

Part3 updates Don't touch me!!!! #42

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

Part3 updates Don't touch me!!!! #42

wants to merge 25 commits into from

Conversation

ST10204902
Copy link
Collaborator

No description provided.

… Implemented LookupHashes instead of raw accountnumbers for transaction field.
Both frontend and backend will not run until .env values are inserted
…out to Transactions. New method transactReceipt in traction route to duplicate lookups across transactions when paying again.

Fixed checkEnvVariables
…de text entry has a chance to be valid. Added sessions to app.js. Updated seedEmployees process. Improved ratelimiter middleware. Added sanitization to transaction routes. Fixed hashHelper use in user route
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

Comment on lines +16 to +19
const employee = await User.findOne({
username: username,
role: "employee"
});

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.

Copilot Autofix AI 2 months ago

To fix the problem, we need to ensure that the user input is properly sanitized or validated before being used in the MongoDB query. One effective way to do this is by using the $eq operator to ensure that the user input is interpreted as a literal value and not as a query object. This approach prevents NoSQL injection attacks by treating the user input as a simple value rather than a potentially malicious query.

In the file server/routes/employee.js, we will modify the query on line 16 to use the $eq operator for the username field. This change ensures that the username is treated as a literal value.

Suggested changeset 1
server/routes/employee.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server/routes/employee.js b/server/routes/employee.js
--- a/server/routes/employee.js
+++ b/server/routes/employee.js
@@ -16,3 +16,3 @@
     const employee = await User.findOne({ 
-      username: username,
+      username: { $eq: username },
       role: "employee"
EOF
@@ -16,3 +16,3 @@
const employee = await User.findOne({
username: username,
username: { $eq: username },
role: "employee"
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
});

// Finding and updating transaction
await Transaction.findById(transactionID).then(

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.

Copilot Autofix AI 2 months ago

To fix the problem, we need to ensure that the user-provided transactionID is treated as a literal value and not as a query object. This can be achieved by using the $eq operator in the MongoDB query. This will ensure that the transactionID is interpreted as a literal value, preventing any potential NoSQL injection attacks.

Suggested changeset 1
server/routes/transaction.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server/routes/transaction.js b/server/routes/transaction.js
--- a/server/routes/transaction.js
+++ b/server/routes/transaction.js
@@ -144,3 +144,3 @@
     // Finding and updating transaction
-    await Transaction.findById(transactionID).then(
+    await Transaction.findOne({ _id: { $eq: transactionID } }).then(
       (transaction) => {
EOF
@@ -144,3 +144,3 @@
// Finding and updating transaction
await Transaction.findById(transactionID).then(
await Transaction.findOne({ _id: { $eq: transactionID } }).then(
(transaction) => {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
const transaction = Transaction.findById(transactionID)
.then(transaction => {
// Finding and updating transaction
await Transaction.findById(transactionID).then(

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.

Copilot Autofix AI 2 months ago

To fix this problem, we need to ensure that the user-provided transactionID is treated as a literal value and not as a query object. This can be achieved by using the $eq operator in the MongoDB query. This will ensure that the transactionID is interpreted as a literal value, thus preventing any potential NoSQL injection attacks.

Suggested changeset 1
server/routes/transaction.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server/routes/transaction.js b/server/routes/transaction.js
--- a/server/routes/transaction.js
+++ b/server/routes/transaction.js
@@ -144,3 +144,3 @@
     // Finding and updating transaction
-    await Transaction.findById(transactionID).then(
+    await Transaction.findById({ _id: { $eq: transactionID } }).then(
       (transaction) => {
@@ -171,3 +171,3 @@
     // Finding and updating transaction
-    await Transaction.findById(transactionID).then(
+    await Transaction.findById({ _id: { $eq: transactionID } }).then(
       (transaction) => {
EOF
@@ -144,3 +144,3 @@
// Finding and updating transaction
await Transaction.findById(transactionID).then(
await Transaction.findById({ _id: { $eq: transactionID } }).then(
(transaction) => {
@@ -171,3 +171,3 @@
// Finding and updating transaction
await Transaction.findById(transactionID).then(
await Transaction.findById({ _id: { $eq: transactionID } }).then(
(transaction) => {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Comment on lines +210 to +213
const originalTransaction = await Transaction.findOne({
recipientAccountNumber: recipientAccountNumber,
approvalStatus: 'completed'
});

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.

Copilot Autofix AI 2 months ago

To fix the problem, we need to ensure that the user-provided recipientAccountNumber is treated as a literal value in the MongoDB query. This can be achieved by using the $eq operator, which ensures that the input is interpreted as a literal value and not as a query object. This change will prevent any potential NoSQL injection attacks.

Suggested changeset 1
server/routes/transaction.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server/routes/transaction.js b/server/routes/transaction.js
--- a/server/routes/transaction.js
+++ b/server/routes/transaction.js
@@ -210,3 +210,3 @@
     const originalTransaction = await Transaction.findOne({
-      recipientAccountNumber: recipientAccountNumber,
+      recipientAccountNumber: { $eq: recipientAccountNumber },
       approvalStatus: 'completed'
EOF
@@ -210,3 +210,3 @@
const originalTransaction = await Transaction.findOne({
recipientAccountNumber: recipientAccountNumber,
recipientAccountNumber: { $eq: recipientAccountNumber },
approvalStatus: 'completed'
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link

sonarqubecloud bot commented Nov 7, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots
C Reliability Rating on New Code (required ≥ A)
E Security Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

const { username, password } = req.body;

// Find the employee by username and role
const employee = await User.findOne({

Check failure

Code scanning / SonarCloud

NoSQL operations should not be vulnerable to injection attacks

<!--SONAR_ISSUE_KEY:AZMG56GWd5-wTxntWMmT-->Change this code to not construct database queries directly from user-controlled data. <p>See more on <a href="https://sonarcloud.io/project/issues?id=APDS7311POE-ST10144453_APDS7311-POE&issues=AZMG56GWd5-wTxntWMmT&open=AZMG56GWd5-wTxntWMmT&pullRequest=42">SonarCloud</a></p>
} = req.body;

// Find recipient using the lookup hash from the original transaction
const originalTransaction = await Transaction.findOne({

Check failure

Code scanning / SonarCloud

NoSQL operations should not be vulnerable to injection attacks

<!--SONAR_ISSUE_KEY:AZMG56Gqd5-wTxntWMmU-->Change this code to not construct database queries directly from user-controlled data. <p>See more on <a href="https://sonarcloud.io/project/issues?id=APDS7311POE-ST10144453_APDS7311-POE&issues=AZMG56Gqd5-wTxntWMmU&open=AZMG56Gqd5-wTxntWMmU&pullRequest=42">SonarCloud</a></p>
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.

1 participant