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

601 allow user defined vector dbs as a destination #623

Merged

Conversation

iandjx
Copy link
Collaborator

@iandjx iandjx commented Oct 30, 2024

No description provided.

ragyabraham and others added 30 commits September 17, 2024 12:03
…ues to string before pushing to vector store
…ring that rows are sub-chunked correctly. Text is cleaned up
…ll text. set the rabbitmq host in the webapp to use the correct env variable
Builtin support for relationships can make it easy for us to fetch which datasource objects use which vectordb
Add Mongoose Schema for Vectordb and Datasource Models
… introduced update creds function for vectordatabase trait that allows us to update api keys for qdrant and pinecone

if (!callback) {
fetchVectorDbFormData?.();
router.push(`/${resourceSlug}/vectordbs`);

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.

Copilot Autofix AI 8 days ago

To fix the problem, we need to ensure that the resourceSlug value is validated against a list of authorized redirects before using it in the URL redirection. This can be achieved by maintaining a list of allowed resourceSlug values and checking if the provided resourceSlug is in that list before performing the redirection.

  1. Create a list of authorized resourceSlug values.
  2. Check if the resourceSlug value is in the list of authorized values before using it in the URL redirection.
  3. If the resourceSlug is not authorized, handle the error appropriately (e.g., show an error message or redirect to a default safe page).
Suggested changeset 1
webapp/src/components/vectordbs/VectorDbForm.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/webapp/src/components/vectordbs/VectorDbForm.tsx b/webapp/src/components/vectordbs/VectorDbForm.tsx
--- a/webapp/src/components/vectordbs/VectorDbForm.tsx
+++ b/webapp/src/components/vectordbs/VectorDbForm.tsx
@@ -35,2 +35,3 @@
 	const { resourceSlug } = router.query;
+	const authorizedResourceSlugs = ['allowedSlug1', 'allowedSlug2', 'allowedSlug3']; // Add your authorized slugs here
 
@@ -65,3 +66,7 @@
 						fetchVectorDbFormData?.();
-						router.push(`/${resourceSlug}/vectordbs`);
+						if (authorizedResourceSlugs.includes(resourceSlug)) {
+							router.push(`/${resourceSlug}/vectordbs`);
+						} else {
+							toast.error('Unauthorized resource slug');
+						}
 					}
EOF
@@ -35,2 +35,3 @@
const { resourceSlug } = router.query;
const authorizedResourceSlugs = ['allowedSlug1', 'allowedSlug2', 'allowedSlug3']; // Add your authorized slugs here

@@ -65,3 +66,7 @@
fetchVectorDbFormData?.();
router.push(`/${resourceSlug}/vectordbs`);
if (authorizedResourceSlugs.includes(resourceSlug)) {
router.push(`/${resourceSlug}/vectordbs`);
} else {
toast.error('Unauthorized resource slug');
}
}
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
toast.success('VectorDb Added');
if (!callback) {
fetchVectorDbFormData?.();
router.push(`/${resourceSlug}/vectordbs`);

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.

Copilot Autofix AI 8 days ago

To fix the problem, we need to ensure that the resourceSlug value is validated against a list of authorized redirects before using it in the URL redirection. This can be achieved by maintaining a list of valid resourceSlug values and checking if the provided resourceSlug is in that list before performing the redirection.

  1. Create a list of authorized resourceSlug values.
  2. Check if the resourceSlug value is in the list of authorized values before using it in the URL redirection.
  3. If the resourceSlug is not authorized, handle the error appropriately (e.g., show an error message or redirect to a default page).
Suggested changeset 1
webapp/src/components/vectordbs/VectorDbForm.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/webapp/src/components/vectordbs/VectorDbForm.tsx b/webapp/src/components/vectordbs/VectorDbForm.tsx
--- a/webapp/src/components/vectordbs/VectorDbForm.tsx
+++ b/webapp/src/components/vectordbs/VectorDbForm.tsx
@@ -35,2 +35,3 @@
 	const { resourceSlug } = router.query;
+	const authorizedResourceSlugs = ['validSlug1', 'validSlug2', 'validSlug3']; // Add your authorized slugs here
 
@@ -81,3 +82,7 @@
 						fetchVectorDbFormData?.();
-						router.push(`/${resourceSlug}/vectordbs`);
+						if (authorizedResourceSlugs.includes(resourceSlug)) {
+							router.push(`/${resourceSlug}/vectordbs`);
+						} else {
+							toast.error('Invalid resource slug');
+						}
 					}
EOF
@@ -35,2 +35,3 @@
const { resourceSlug } = router.query;
const authorizedResourceSlugs = ['validSlug1', 'validSlug2', 'validSlug3']; // Add your authorized slugs here

@@ -81,3 +82,7 @@
fetchVectorDbFormData?.();
router.push(`/${resourceSlug}/vectordbs`);
if (authorizedResourceSlugs.includes(resourceSlug)) {
router.push(`/${resourceSlug}/vectordbs`);
} else {
toast.error('Invalid resource slug');
}
}
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
{vectorDbs.map(vectorDb => (
<tr
key={vectorDb._id}
onClick={() => router.push(`/${resourceSlug}/vectordb/${vectorDb._id}/edit`)}

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.

Copilot Autofix AI 8 days ago

To fix the problem, we should avoid using user input directly in the URL redirection. Instead, we can maintain a list of authorized redirects and validate the resourceSlug against this list before constructing the URL. This ensures that only safe, predefined values are used in the redirection.

  1. Create a list of authorized resourceSlug values.
  2. Validate the resourceSlug against this list before using it in the URL construction.
  3. If the resourceSlug is not in the list, handle the error appropriately (e.g., redirect to a default page or show an error message).
Suggested changeset 1
webapp/src/components/vectordbs/VectorDbTable.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/webapp/src/components/vectordbs/VectorDbTable.tsx b/webapp/src/components/vectordbs/VectorDbTable.tsx
--- a/webapp/src/components/vectordbs/VectorDbTable.tsx
+++ b/webapp/src/components/vectordbs/VectorDbTable.tsx
@@ -24,2 +24,4 @@
 	const { resourceSlug } = router.query;
+	const authorizedResourceSlugs = ['authorizedSlug1', 'authorizedSlug2']; // Add all authorized slugs here
+	const isValidResourceSlug = authorizedResourceSlugs.includes(resourceSlug);
 	const [deletingVectorDb, setDeletingVectorDb] = useState(null);
@@ -121,3 +123,10 @@
 								key={vectorDb._id}
-								onClick={() => router.push(`/${resourceSlug}/vectordb/${vectorDb._id}/edit`)}
+								onClick={() => {
+									if (isValidResourceSlug) {
+										router.push(`/${resourceSlug}/vectordb/${vectorDb._id}/edit`);
+									} else {
+										// Handle invalid resourceSlug, e.g., redirect to a default page or show an error
+										router.push('/defaultPage');
+									}
+								}}
 								className={cn(
EOF
@@ -24,2 +24,4 @@
const { resourceSlug } = router.query;
const authorizedResourceSlugs = ['authorizedSlug1', 'authorizedSlug2']; // Add all authorized slugs here
const isValidResourceSlug = authorizedResourceSlugs.includes(resourceSlug);
const [deletingVectorDb, setDeletingVectorDb] = useState(null);
@@ -121,3 +123,10 @@
key={vectorDb._id}
onClick={() => router.push(`/${resourceSlug}/vectordb/${vectorDb._id}/edit`)}
onClick={() => {
if (isValidResourceSlug) {
router.push(`/${resourceSlug}/vectordb/${vectorDb._id}/edit`);
} else {
// Handle invalid resourceSlug, e.g., redirect to a default page or show an error
router.push('/defaultPage');
}
}}
className={cn(
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
server.get('/register', unauthedMiddlewareChain, checkSessionWelcome, renderStaticPage(app, '/register'));
server.get(
'/login',
unauthedMiddlewareChain,

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.
webapp/src/router.ts Dismissed Show dismissed Hide dismissed
@@ -717,6 +725,32 @@
variableController.deleteVariableApi
);

teamRouter.get('/vectordbs.json', vectorDbController.vectorDbsJson);

teamRouter.get('/vectordb/:vectorDbId([a-f0-9]{24}).json', vectorDbController.vectorDbJson);

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.
teamRouter.delete(
'/forms/vectordb/:vectorDbId',
hasPerms.one(Permissions.DELETE_VECTOR_DB),
vectorDbController.deleteVectorDbApi

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.

Copilot Autofix AI 8 days ago

To fix the problem, we need to introduce rate limiting to the route handler that performs the database access. We can use the express-rate-limit package to achieve this. The rate limiter will be configured to allow a certain number of requests per window of time (e.g., 100 requests per 15 minutes) and will be applied to the specific route handler.

  1. Install the express-rate-limit package if it is not already installed.
  2. Import the express-rate-limit package in the webapp/src/router.ts file.
  3. Configure the rate limiter with appropriate settings.
  4. Apply the rate limiter to the deleteVectorDbApi route handler.
Suggested changeset 2
webapp/src/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/webapp/src/router.ts b/webapp/src/router.ts
--- a/webapp/src/router.ts
+++ b/webapp/src/router.ts
@@ -29,2 +29,3 @@
 import fileUpload from 'express-fileupload';
+import RateLimit from 'express-rate-limit';
 import Permissions from 'permissions/permissions';
@@ -55,2 +56,7 @@
 
+const limiter = RateLimit({
+	windowMs: 15 * 60 * 1000, // 15 minutes
+	max: 100, // max 100 requests per windowMs
+});
+
 export default function router(server, app) {
@@ -751,2 +757,3 @@
 		hasPerms.one(Permissions.DELETE_VECTOR_DB),
+		limiter,
 		vectorDbController.deleteVectorDbApi
EOF
@@ -29,2 +29,3 @@
import fileUpload from 'express-fileupload';
import RateLimit from 'express-rate-limit';
import Permissions from 'permissions/permissions';
@@ -55,2 +56,7 @@

const limiter = RateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // max 100 requests per windowMs
});

export default function router(server, app) {
@@ -751,2 +757,3 @@
hasPerms.one(Permissions.DELETE_VECTOR_DB),
limiter,
vectorDbController.deleteVectorDbApi
webapp/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/webapp/package.json b/webapp/package.json
--- a/webapp/package.json
+++ b/webapp/package.json
@@ -123,3 +123,4 @@
     "tsconfig-paths": "^4.2.0",
-    "uuid": "^9.0.1"
+    "uuid": "^9.0.1",
+    "express-rate-limit": "^7.4.1"
   },
EOF
@@ -123,3 +123,4 @@
"tsconfig-paths": "^4.2.0",
"uuid": "^9.0.1"
"uuid": "^9.0.1",
"express-rate-limit": "^7.4.1"
},
This fix introduces these dependencies
Package Version Security advisories
express-rate-limit (npm) 7.4.1 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
webapp/src/db/vectordb.ts Fixed Show fixed Hide fixed
@ragyabraham ragyabraham merged commit 16cf333 into develop Nov 11, 2024
7 checks passed
@ragyabraham ragyabraham deleted the 601-allow-user-defined-vector-dbs-as-a-destination branch November 11, 2024 22:35
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.

4 participants