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

Release 1.5.0 to main #327

Merged
merged 30 commits into from
Feb 10, 2025
Merged

Release 1.5.0 to main #327

merged 30 commits into from
Feb 10, 2025

Conversation

JeraldJF
Copy link
Collaborator

No description provided.

JeraldJF and others added 30 commits January 7, 2025 19:05
fix: #OBS-I354 dataset level metrics fixes and addition
fix: #OBS-I354 throw alerts on failed events greater than 0
fix: #OBS-I452 Dataset alias attach and detach functionality
fix: #OBS-I452 Dataset in/out apis updated for dataset check using alias
feat: #OBS-I452 : list api changes to return alias name
@JeraldJF JeraldJF changed the title Release 1.5.0 Release 1.5.0 to main Feb 10, 2025
@manjudr manjudr merged commit f2072c9 into main Feb 10, 2025
1 of 2 checks passed
@manjudr manjudr deleted the release-1.5.0 branch February 10, 2025 13:34
const fieldValues = fields ? _.split(fields as string, ",") : [];
const invalidFields = _.difference(fieldValues, Object.keys(DatasetDraft.getAttributes()));
const invalidFields = mode === "edit" ? _.difference(fieldValues, Object.keys(DatasetDraft.getAttributes())) : _.difference(fieldValues, Object.keys(Dataset.getAttributes()));

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 1 month ago

To fix the problem, we need to ensure that the fields parameter is validated before it is processed. Specifically, we should check that the fields parameter is a string and that the resulting fieldValues array has a reasonable length. If the length exceeds a predefined limit, we should throw an error or handle it appropriately.

  1. Add a validation step to check if fields is a string and if the length of fieldValues is within an acceptable range.
  2. If the validation fails, throw an error or return an appropriate response.
Suggested changeset 1
api-service/src/controllers/DatasetRead/DatasetRead.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/DatasetRead/DatasetRead.ts b/api-service/src/controllers/DatasetRead/DatasetRead.ts
--- a/api-service/src/controllers/DatasetRead/DatasetRead.ts
+++ b/api-service/src/controllers/DatasetRead/DatasetRead.ts
@@ -20,2 +20,5 @@
     const { fields, mode } = req.query;
+    if (fields && (typeof fields !== 'string' || fields.length > 1000)) {
+        throw obsrvError(dataset_id, "DATASET_INVALID_FIELDS", `The 'fields' parameter is invalid or too long.`, "BAD_REQUEST", 400);
+    }
     const fieldValues = fields ? _.split(fields as string, ",") : [];
EOF
@@ -20,2 +20,5 @@
const { fields, mode } = req.query;
if (fields && (typeof fields !== 'string' || fields.length > 1000)) {
throw obsrvError(dataset_id, "DATASET_INVALID_FIELDS", `The 'fields' parameter is invalid or too long.`, "BAD_REQUEST", 400);
}
const fieldValues = fields ? _.split(fields as string, ",") : [];
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 fieldValues = fields ? _.split(fields as string, ",") : [];
const invalidFields = _.difference(fieldValues, Object.keys(DatasetDraft.getAttributes()));
const invalidFields = mode === "edit" ? _.difference(fieldValues, Object.keys(DatasetDraft.getAttributes())) : _.difference(fieldValues, Object.keys(Dataset.getAttributes()));

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 1 month ago

To fix the problem, we need to ensure that the fields parameter is either an array or a string that can be safely split into an array. Additionally, we should limit the size of the resulting fieldValues array to prevent excessive resource consumption.

  1. Check if the fields parameter is a string and split it into an array.
  2. Limit the size of the fieldValues array to a reasonable maximum length.
  3. If the fields parameter is not a valid string, default to an empty array.
Suggested changeset 1
api-service/src/controllers/DatasetRead/DatasetRead.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/DatasetRead/DatasetRead.ts b/api-service/src/controllers/DatasetRead/DatasetRead.ts
--- a/api-service/src/controllers/DatasetRead/DatasetRead.ts
+++ b/api-service/src/controllers/DatasetRead/DatasetRead.ts
@@ -20,3 +20,4 @@
     const { fields, mode } = req.query;
-    const fieldValues = fields ? _.split(fields as string, ",") : [];
+    const MAX_FIELDS_LENGTH = 100; // Define a reasonable maximum length for fieldValues
+    const fieldValues = (typeof fields === 'string') ? _.split(fields, ",").slice(0, MAX_FIELDS_LENGTH) : [];
     const invalidFields = mode === "edit" ? _.difference(fieldValues, Object.keys(DatasetDraft.getAttributes())) : _.difference(fieldValues, Object.keys(Dataset.getAttributes()));
EOF
@@ -20,3 +20,4 @@
const { fields, mode } = req.query;
const fieldValues = fields ? _.split(fields as string, ",") : [];
const MAX_FIELDS_LENGTH = 100; // Define a reasonable maximum length for fieldValues
const fieldValues = (typeof fields === 'string') ? _.split(fields, ",").slice(0, MAX_FIELDS_LENGTH) : [];
const invalidFields = mode === "edit" ? _.difference(fieldValues, Object.keys(DatasetDraft.getAttributes())) : _.difference(fieldValues, Object.keys(Dataset.getAttributes()));
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
@@ -62,6 +63,7 @@
router.get("/connectors/read/:id", setDataToRequestObject("api.connectors.read"), onRequest({entity: Entity.Management }), telemetryAuditStart({action: telemetryActions.readConnectors, operationType: OperationType.GET}), checkRBAC.handler(), ConnectorsRead);
router.post("/datasets/import", setDataToRequestObject("api.datasets.import"), onRequest({ entity: Entity.Management }), checkRBAC.handler(), DatasetImport);
router.post("/connector/register", setDataToRequestObject("api.connector.register"), onRequest({ entity: Entity.Management }), connectorRegisterController);
router.post("/datasets/alias", setDataToRequestObject("api.datasets.alias"), onRequest({ entity: Entity.Management }), checkRBAC.handler(), datasetAlias);

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.

Copilot Autofix AI about 1 month ago

To fix the problem, we need to introduce rate limiting to the Express application. The best way to do this is by using the express-rate-limit package, which allows us to easily set up rate limiting middleware. We will configure the rate limiter to allow a maximum of 100 requests per 15 minutes and apply it to all routes.

  1. Install the express-rate-limit package.
  2. Import the express-rate-limit package in the Router.ts file.
  3. Configure the rate limiter with the desired settings.
  4. Apply the rate limiter to all routes.
Suggested changeset 2
api-service/src/routes/Router.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/routes/Router.ts b/api-service/src/routes/Router.ts
--- a/api-service/src/routes/Router.ts
+++ b/api-service/src/routes/Router.ts
@@ -1,2 +1,3 @@
 import express from "express";
+import rateLimit from "express-rate-limit";
 import dataIn from "../controllers/DataIngestion/DataIngestionController";
@@ -38,4 +39,10 @@
 
+const limiter = rateLimit({
+    windowMs: 15 * 60 * 1000, // 15 minutes
+    max: 100, // limit each IP to 100 requests per windowMs
+});
+
 export const router = express.Router();
 
+router.use(limiter);
 router.post("/data/in/:dataset_id", setDataToRequestObject("api.data.in"), onRequest({ entity: Entity.Data_in }), telemetryAuditStart({action: telemetryActions.createDataset, operationType: OperationType.CREATE}), checkRBAC.handler(), dataIn);
EOF
@@ -1,2 +1,3 @@
import express from "express";
import rateLimit from "express-rate-limit";
import dataIn from "../controllers/DataIngestion/DataIngestionController";
@@ -38,4 +39,10 @@

const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
});

export const router = express.Router();

router.use(limiter);
router.post("/data/in/:dataset_id", setDataToRequestObject("api.data.in"), onRequest({ entity: Entity.Data_in }), telemetryAuditStart({action: telemetryActions.createDataset, operationType: OperationType.CREATE}), checkRBAC.handler(), dataIn);
api-service/package.json
Outside changed files

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/package.json b/api-service/package.json
--- a/api-service/package.json
+++ b/api-service/package.json
@@ -68,3 +68,4 @@
     "winston": "~2.4.3",
-    "winston-daily-rotate-file": "~3.2.1"
+    "winston-daily-rotate-file": "~3.2.1",
+    "express-rate-limit": "^7.5.0"
   },
EOF
@@ -68,3 +68,4 @@
"winston": "~2.4.3",
"winston-daily-rotate-file": "~3.2.1"
"winston-daily-rotate-file": "~3.2.1",
"express-rate-limit": "^7.5.0"
},
This fix introduces these dependencies
Package Version Security advisories
express-rate-limit (npm) 7.5.0 None
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
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.

3 participants