1
0
Fork 0
mirror of synced 2024-07-04 22:11:23 +12:00

Prevent the key user being used in rest queries (#12072)

* Add warning about unusable user binding

* linting

* remove unnecessary safe nav operators

* change regex to capture property access of user binding
This commit is contained in:
Gerard Burns 2023-10-26 13:06:25 +01:00 committed by GitHub
parent 5909b4a7c7
commit 44f9c64ed7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -196,8 +196,36 @@
}
}
const validateQuery = async () => {
const forbiddenBindings = /{{\s?user(\.(\w|\$)*\s?|\s?)}}/g
const bindingError = new Error(
"'user' is a protected binding and cannot be used"
)
if (forbiddenBindings.test(url)) {
throw bindingError
}
if (forbiddenBindings.test(query.fields.requestBody ?? "")) {
throw bindingError
}
Object.values(requestBindings).forEach(bindingValue => {
if (forbiddenBindings.test(bindingValue)) {
throw bindingError
}
})
Object.values(query.fields.headers).forEach(headerValue => {
if (forbiddenBindings.test(headerValue)) {
throw bindingError
}
})
}
async function runQuery() {
try {
await validateQuery()
response = await queries.preview(buildQuery())
if (response.rows.length === 0) {
notifications.info("Request did not return any data")