Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2391,19 +2391,38 @@ export class Stack {
}

private sanitizeIQuery(query: IQuery): boolean {
const allowedKeys = {
_content_type_uid: 'string',
uid: 'string',
_version: {
$exists: 'boolean'
},
locale: 'string'
};

const validateObject = (obj: any, schema: any): boolean => {
for (const key in obj) {
if (!schema.hasOwnProperty(key)) {
return false;
}
if (typeof schema[key] === 'object') {
if (!validateObject(obj[key], schema[key])) {
return false;
}
} else if (typeof obj[key] !== schema[key]) {
return false;
}
}
return true;
};
if (!query || typeof query !== 'object' || Array.isArray(query)) {
return false;
}
if (!query || !Array.isArray(query.$or)) {
if (!query.$or || !Array.isArray(query.$or)) {
return false;
}
for (const item of query.$or) {
if (
typeof item._content_type_uid !== 'string' ||
typeof item.uid !== 'string' ||
(item._version && typeof item._version.$exists !== 'boolean') ||
(item.locale && typeof item.locale !== 'string')
) {
if (!validateObject(item, allowedKeys)) {
return false;
}
}
Expand Down
Loading