Skip to content

Commit 5527388

Browse files
Copilothotlong
andcommitted
Add input validation to getObjectSchema implementations for security
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 09d9669 commit 5527388

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

packages/runner/src/lib/mockDataSource.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class MockDataSource implements DataSource {
4141
}
4242

4343
async getObjectSchema(objectName: string): Promise<any> {
44+
if (!objectName || typeof objectName !== 'string') {
45+
throw new Error('Invalid object name');
46+
}
47+
4448
console.log(`[DataSource] Getting schema for ${objectName}`);
4549
// Return a minimal schema for mock purposes
4650
return {

packages/types/examples/rest-data-source.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,16 @@ export class RestDataSource<T = any> implements DataSource<T> {
171171
* Get object schema/metadata
172172
*/
173173
async getObjectSchema(objectName: string): Promise<any> {
174-
const url = `${this.baseUrl}/_schema/${objectName}`;
174+
if (!objectName || typeof objectName !== 'string') {
175+
throw new Error('Invalid object name');
176+
}
177+
178+
// Validate object name to prevent path traversal
179+
if (objectName.includes('/') || objectName.includes('\\') || objectName.includes('..')) {
180+
throw new Error('Invalid object name: must not contain path separators');
181+
}
182+
183+
const url = `${this.baseUrl}/_schema/${encodeURIComponent(objectName)}`;
175184

176185
const response = await fetch(url);
177186

0 commit comments

Comments
 (0)