Skip to content

Commit 4a33fa8

Browse files
committed
chore: make sure that db/coll are in the untrusted data wrapper
1 parent 253e49c commit 4a33fa8

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/tools/mongodb/search/listSearchIndexes.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class ListSearchIndexesTool extends MongoDBToolBase {
3333
} else {
3434
return {
3535
content: formatUntrustedData(
36+
"Could not retrieve search indexes",
3637
`There are no search or vector search indexes in ${database}.${collection}`
3738
),
3839
};
@@ -69,14 +70,7 @@ export class ListSearchIndexesTool extends MongoDBToolBase {
6970
],
7071
};
7172
} else {
72-
return {
73-
content: [
74-
{
75-
text: `Could not retrieve indexes in ${database}.${collection}: ${EJSON.stringify(error)}.`,
76-
type: "text",
77-
},
78-
],
79-
};
73+
return { content: formatUntrustedData("Could not retrieve search indexes", EJSON.stringify(error)) };
8074
}
8175
}
8276
}

tests/integration/tools/mongodb/search/listSearchIndexes.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
validateThrowsForInvalidArguments,
88
databaseCollectionInvalidArgs,
99
sleep,
10+
getDataFromUntrustedContent,
1011
} from "../../../helpers.js";
1112
import type { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver";
1213
import type { SearchIndexStatus } from "../../../../../src/tools/mongodb/search/listSearchIndexes.js";
@@ -54,7 +55,9 @@ describeWithMongoDB(
5455
name: "list-search-indexes",
5556
arguments: { database: "any", collection: "foo" },
5657
});
57-
const content = getResponseContent(response.content);
58+
const responseContent = getResponseContent(response.content);
59+
const content = getDataFromUntrustedContent(responseContent);
60+
expect(responseContent).toContain("Could not retrieve search indexes");
5861
expect(content).toEqual("There are no search or vector search indexes in any.foo");
5962
});
6063
});
@@ -65,7 +68,9 @@ describeWithMongoDB(
6568
name: "list-search-indexes",
6669
arguments: { database: "any", collection: "foo" },
6770
});
68-
const content = getResponseContent(response.content);
71+
const responseContent = getResponseContent(response.content);
72+
const content = getDataFromUntrustedContent(responseContent);
73+
expect(responseContent).toContain("Could not retrieve search indexes");
6974
expect(content).toEqual("There are no search or vector search indexes in any.foo");
7075
});
7176
});

0 commit comments

Comments
 (0)