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

#OBS-I335: dataset update fix #276

Merged
merged 5 commits into from
Nov 13, 2024
Merged

#OBS-I335: dataset update fix #276

merged 5 commits into from
Nov 13, 2024

Conversation

JeraldJF
Copy link

No description provided.

const removeConfigs = _.map(_.filter(newConfigs, {action: "remove"}), "value.field_key")
const addConfigs = _.map(_.filter(newConfigs, {action: "upsert"}), "value")
if (newConfigs) {
const removeConfigs = _.map(_.filter(newConfigs, { action: "remove" }), "value.field_key")

Check failure

Code scanning / CodeQL

Loop bound injection High

Iteration over a user-controlled object with a potentially unbounded .length property from a
user-provided value
.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that the newConfigs object is a valid array and has a reasonable length before using it in the loop. We can achieve this by adding a check to confirm that newConfigs is an array and limiting its length to a safe maximum value.

  • First, we will check if newConfigs is an array using Array.isArray.
  • Then, we will limit the length of newConfigs to a maximum value (e.g., 1000) to prevent potential DoS attacks.
Suggested changeset 1
api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
--- a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
+++ b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
@@ -157,5 +157,7 @@
     let updatedConfigs = currentConfigs;
-    if (newConfigs && newConfigs.length) {
-        const removeConfigs = _.map(_.filter(newConfigs, { action: "remove" }), "value.field_key")
-        const addConfigs = _.map(_.filter(newConfigs, { action: "upsert" }), "value")
+    if (Array.isArray(newConfigs) && newConfigs.length > 0) {
+        const maxLength = 1000;
+        const validNewConfigs = newConfigs.slice(0, maxLength);
+        const removeConfigs = _.map(_.filter(validNewConfigs, { action: "remove" }), "value.field_key")
+        const addConfigs = _.map(_.filter(validNewConfigs, { action: "upsert" }), "value")
 
EOF
@@ -157,5 +157,7 @@
let updatedConfigs = currentConfigs;
if (newConfigs && newConfigs.length) {
const removeConfigs = _.map(_.filter(newConfigs, { action: "remove" }), "value.field_key")
const addConfigs = _.map(_.filter(newConfigs, { action: "upsert" }), "value")
if (Array.isArray(newConfigs) && newConfigs.length > 0) {
const maxLength = 1000;
const validNewConfigs = newConfigs.slice(0, maxLength);
const removeConfigs = _.map(_.filter(validNewConfigs, { action: "remove" }), "value.field_key")
const addConfigs = _.map(_.filter(validNewConfigs, { action: "upsert" }), "value")

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 addConfigs = _.map(_.filter(newConfigs, {action: "upsert"}), "value")
if (newConfigs) {
const removeConfigs = _.map(_.filter(newConfigs, { action: "remove" }), "value.field_key")
const addConfigs = _.map(_.filter(newConfigs, { action: "upsert" }), "value")

Check failure

Code scanning / CodeQL

Loop bound injection High

Iteration over a user-controlled object with a potentially unbounded .length property from a
user-provided value
.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that newConfigs is an array before using its .length property in the loop. This can be done by adding a check to confirm that newConfigs is an instance of Array. If it is not, we can either initialize it as an empty array or handle the error appropriately.

Steps to fix:

  1. Add a check to ensure newConfigs is an array before using it in the loop.
  2. If newConfigs is not an array, initialize it as an empty array or handle the error.
Suggested changeset 1
api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
--- a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
+++ b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
@@ -157,3 +157,3 @@
     let updatedConfigs = currentConfigs;
-    if (newConfigs && newConfigs.length) {
+    if (Array.isArray(newConfigs) && newConfigs.length) {
         const removeConfigs = _.map(_.filter(newConfigs, { action: "remove" }), "value.field_key")
EOF
@@ -157,3 +157,3 @@
let updatedConfigs = currentConfigs;
if (newConfigs && newConfigs.length) {
if (Array.isArray(newConfigs) && newConfigs.length) {
const removeConfigs = _.map(_.filter(newConfigs, { action: "remove" }), "value.field_key")
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 removeConfigs = _.map(_.filter(newConfig.denorm_fields, {action: "remove"}), "value.denorm_out_field")
const addConfigs = _.map(_.filter(newConfig.denorm_fields, {action: "upsert"}), "value")
if (newConfig) {
const removeConfigs = _.map(_.filter(newConfig.denorm_fields, { action: "remove" }), "value.denorm_out_field")

Check failure

Code scanning / CodeQL

Loop bound injection High

Iteration over a user-controlled object with a potentially unbounded .length property from a
user-provided value
.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that newConfig.denorm_fields is an array and limit its length to a reasonable number before iterating over it. This can be done by adding a validation check before the loop.

  1. Check if newConfig.denorm_fields is an array.
  2. Limit the length of newConfig.denorm_fields to a reasonable maximum value (e.g., 1000) to prevent potential DoS attacks.
Suggested changeset 1
api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
--- a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
+++ b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
@@ -178,5 +178,6 @@
     let updatedConfigs = currentConfig.denorm_fields;
-    if (_.get(newConfig, "denorm_fields")) {
-        const removeConfigs = _.map(_.filter(newConfig.denorm_fields, { action: "remove" }), "value.denorm_out_field")
-        const addConfigs = _.map(_.filter(newConfig.denorm_fields, { action: "upsert" }), "value")
+    const denormFields = _.get(newConfig, "denorm_fields");
+    if (Array.isArray(denormFields) && denormFields.length <= 1000) {
+        const removeConfigs = _.map(_.filter(denormFields, { action: "remove" }), "value.denorm_out_field")
+        const addConfigs = _.map(_.filter(denormFields, { action: "upsert" }), "value")
 
EOF
@@ -178,5 +178,6 @@
let updatedConfigs = currentConfig.denorm_fields;
if (_.get(newConfig, "denorm_fields")) {
const removeConfigs = _.map(_.filter(newConfig.denorm_fields, { action: "remove" }), "value.denorm_out_field")
const addConfigs = _.map(_.filter(newConfig.denorm_fields, { action: "upsert" }), "value")
const denormFields = _.get(newConfig, "denorm_fields");
if (Array.isArray(denormFields) && denormFields.length <= 1000) {
const removeConfigs = _.map(_.filter(denormFields, { action: "remove" }), "value.denorm_out_field")
const addConfigs = _.map(_.filter(denormFields, { action: "upsert" }), "value")

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 addConfigs = _.map(_.filter(newConfig.denorm_fields, {action: "upsert"}), "value")
if (newConfig) {
const removeConfigs = _.map(_.filter(newConfig.denorm_fields, { action: "remove" }), "value.denorm_out_field")
const addConfigs = _.map(_.filter(newConfig.denorm_fields, { action: "upsert" }), "value")

Check failure

Code scanning / CodeQL

Loop bound injection High

Iteration over a user-controlled object with a potentially unbounded .length property from a
user-provided value
.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that newConfig.denorm_fields is a valid array before using its length property in the loop. This can be done by adding a check to confirm that newConfig.denorm_fields is an array and has a reasonable length. If it is not, we should handle the error appropriately.

Suggested changeset 1
api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
--- a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
+++ b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
@@ -178,3 +178,3 @@
     let updatedConfigs = currentConfig.denorm_fields;
-    if (_.get(newConfig, "denorm_fields")) {
+    if (_.get(newConfig, "denorm_fields") && Array.isArray(newConfig.denorm_fields) && newConfig.denorm_fields.length < 1000) { // Validate newConfig.denorm_fields
         const removeConfigs = _.map(_.filter(newConfig.denorm_fields, { action: "remove" }), "value.denorm_out_field")
EOF
@@ -178,3 +178,3 @@
let updatedConfigs = currentConfig.denorm_fields;
if (_.get(newConfig, "denorm_fields")) {
if (_.get(newConfig, "denorm_fields") && Array.isArray(newConfig.denorm_fields) && newConfig.denorm_fields.length < 1000) { // Validate newConfig.denorm_fields
const removeConfigs = _.map(_.filter(newConfig.denorm_fields, { action: "remove" }), "value.denorm_out_field")
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
@@ -178,8 +190,8 @@

const mergeConnectorsConfig = (currConfigs: any, newConfigs: any) => {

const removeConfigs = _.map(_.filter(newConfigs, {action: "remove"}), "value.connector_id")
const addConfigs = _.map(_.filter(newConfigs, {action: "upsert"}), "value")
const removeConfigs = _.map(_.filter(newConfigs, { action: "remove" }), "value.connector_id")

Check failure

Code scanning / CodeQL

Loop bound injection High

Iteration over a user-controlled object with a potentially unbounded .length property from a
user-provided value
.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that newConfigs is an array before using its .length property in the loop. This can be done by adding a check to confirm that newConfigs is an instance of an array. If it is not, we should handle the error appropriately, possibly by returning an empty array or an error response.

Suggested changeset 1
api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
--- a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
+++ b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
@@ -200,2 +200,6 @@
 
+    if (!Array.isArray(newConfigs)) {
+        throw new Error("Invalid input: newConfigs should be an array");
+    }
+
     const removeConfigs = _.map(_.filter(newConfigs, { action: "remove" }), "value.connector_id")
EOF
@@ -200,2 +200,6 @@

if (!Array.isArray(newConfigs)) {
throw new Error("Invalid input: newConfigs should be an array");
}

const removeConfigs = _.map(_.filter(newConfigs, { action: "remove" }), "value.connector_id")
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 removeConfigs = _.map(_.filter(newConfigs, {action: "remove"}), "value.connector_id")
const addConfigs = _.map(_.filter(newConfigs, {action: "upsert"}), "value")
const removeConfigs = _.map(_.filter(newConfigs, { action: "remove" }), "value.connector_id")
const addConfigs = _.map(_.filter(newConfigs, { action: "upsert" }), "value")

Check failure

Code scanning / CodeQL

Loop bound injection High

Iteration over a user-controlled object with a potentially unbounded .length property from a
user-provided value
.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that newConfigs is an array before using its .length property in a loop. This can be done by adding a check to confirm that newConfigs is an instance of Array. If it is not, we should handle the error appropriately, such as returning an empty array or throwing an error.

Suggested changeset 1
api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
--- a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
+++ b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
@@ -200,2 +200,6 @@
 
+    if (!(newConfigs instanceof Array)) {
+        throw new Error("Invalid input: newConfigs must be an array");
+    }
+
     const removeConfigs = _.map(_.filter(newConfigs, { action: "remove" }), "value.connector_id")
EOF
@@ -200,2 +200,6 @@

if (!(newConfigs instanceof Array)) {
throw new Error("Invalid input: newConfigs must be an array");
}

const removeConfigs = _.map(_.filter(newConfigs, { action: "remove" }), "value.connector_id")
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 mergeTags = (currentTags: any, newConfigs: any) => {

const tagsToRemove = _.map(_.filter(newConfigs, {action: "remove"}), "value")
const tagsToAdd = _.map(_.filter(newConfigs, {action: "upsert"}), "value")
const tagsToRemove = _.map(_.filter(newConfigs, { action: "remove" }), "value")

Check failure

Code scanning / CodeQL

Loop bound injection High

Iteration over a user-controlled object with a potentially unbounded .length property from a
user-provided value
.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that newConfigs is an array before using its .length property in a loop. This can be done by adding a check to verify that newConfigs is an instance of Array. If it is not, we should handle the error appropriately, such as returning an empty array or throwing an error.

Suggested changeset 1
api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
--- a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
+++ b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
@@ -222,2 +222,6 @@
 
+    if (!(newConfigs instanceof Array)) {
+        throw new Error("Invalid input: newConfigs must be an array");
+    }
+
     const tagsToRemove = _.map(_.filter(newConfigs, { action: "remove" }), "value")
EOF
@@ -222,2 +222,6 @@

if (!(newConfigs instanceof Array)) {
throw new Error("Invalid input: newConfigs must be an array");
}

const tagsToRemove = _.map(_.filter(newConfigs, { action: "remove" }), "value")
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 tagsToRemove = _.map(_.filter(newConfigs, {action: "remove"}), "value")
const tagsToAdd = _.map(_.filter(newConfigs, {action: "upsert"}), "value")
const tagsToRemove = _.map(_.filter(newConfigs, { action: "remove" }), "value")
const tagsToAdd = _.map(_.filter(newConfigs, { action: "upsert" }), "value")

Check failure

Code scanning / CodeQL

Loop bound injection High

Iteration over a user-controlled object with a potentially unbounded .length property from a
user-provided value
.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that newConfigs is an array before using its .length property in a loop. This can be done by adding a check to verify that newConfigs is an instance of an array. If it is not, we should handle the error appropriately, such as returning an empty array or throwing an error.

Suggested changeset 1
api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
--- a/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
+++ b/api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
@@ -222,2 +222,6 @@
 
+    if (!Array.isArray(newConfigs)) {
+        throw new Error("Invalid input: newConfigs must be an array");
+    }
+
     const tagsToRemove = _.map(_.filter(newConfigs, { action: "remove" }), "value")
EOF
@@ -222,2 +222,6 @@

if (!Array.isArray(newConfigs)) {
throw new Error("Invalid input: newConfigs must be an array");
}

const tagsToRemove = _.map(_.filter(newConfigs, { action: "remove" }), "value")
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
@SanthoshVasabhaktula SanthoshVasabhaktula merged commit 25ec1f0 into main Nov 13, 2024
1 of 3 checks passed
@SanthoshVasabhaktula SanthoshVasabhaktula deleted the hudi-spec-fix branch November 13, 2024 09:26
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