Skip to content

Implement safer ArangoDB queries#8351

Merged
auvipy merged 13 commits intocelery:mainfrom
othieno:arangodb-bugfixes
Jul 29, 2023
Merged

Implement safer ArangoDB queries#8351
auvipy merged 13 commits intocelery:mainfrom
othieno:arangodb-bugfixes

Conversation

@othieno
Copy link
Copy Markdown
Contributor

@othieno othieno commented Jul 1, 2023

The AQL queries used in the ArangoDbBackend's implementation are potentially
vulnerable to injections because no sanity checks are performed on the
arguments used to build the query strings.

This is particularly evident when using a database collection with a dash in
its name, e.g. "celery-task-results". The query string generated by the set
method is 'INSERT {task: v}, _key: "k"} INTO celery-task-results' instead of
'INSERT {task: v}, _key: "k"} INTO celery-task-results' (backticks
surrounding collection name). The former is evaluated as a substraction
(celery - task - results) and is therefore an illegal collection name,
while the latter is evaluated as a string.

This commit re-implements the setter and getters using bind parameters,
which performs the necessary safety checks. Furthermore, the new query used
in the set method accounts for updates to existing keys, resolving #7039.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 1, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.24% 🎉

Comparison is base (f5e6034) 87.07% compared to head (e53cef9) 87.32%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8351      +/-   ##
==========================================
+ Coverage   87.07%   87.32%   +0.24%     
==========================================
  Files         148      148              
  Lines       18492    18458      -34     
  Branches     3152     3148       -4     
==========================================
+ Hits        16102    16118      +16     
+ Misses       2110     2061      -49     
+ Partials      280      279       -1     
Flag Coverage Δ
unittests 87.29% <100.00%> (+0.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
celery/backends/arangodb.py 97.56% <100.00%> (+42.38%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@auvipy auvipy self-requested a review July 2, 2023 07:36
@othieno othieno force-pushed the arangodb-bugfixes branch from fd8a3dd to 29d7990 Compare July 25, 2023 00:59
Copy link
Copy Markdown
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having improved test coverage for all the methods would be great

Jeremy Z. Othieno and others added 9 commits July 26, 2023 01:56
The AQL queries used in the ArangoDbBackend's implementation are potentially
vulnerable to injections because no sanity checks are performed on the
arguments used to build the query strings.

This is particularly evident when using a database collection with a dash in
its name, e.g. "celery-task-results". The query string generated by the set
method is 'INSERT {task: v}, _key: "k"} INTO celery-task-results' instead of
'INSERT {task: v}, _key: "k"} INTO `celery-task-results`' (backticks
surrounding collection name). The former is evaluated as a substraction
(celery - task - results) and is therefore an illegal collection name,
while the latter is evaluated as a string.

This commit re-implements the setter and getters using bind parameters[1],
which performs the necessary safety checks. Furthermore, the new query used
in the set method accounts for updates to existing keys, resolving celery#7039.

[1] https://www.arangodb.com/docs/stable/aql/fundamentals-bind-parameters.html
@othieno othieno force-pushed the arangodb-bugfixes branch from 6afa0c4 to 9ae1e38 Compare July 25, 2023 23:57
@othieno othieno force-pushed the arangodb-bugfixes branch from c2f7224 to ad0dedc Compare July 26, 2023 19:31
@othieno othieno marked this pull request as ready for review July 27, 2023 12:06
@auvipy
Copy link
Copy Markdown
Member

auvipy commented Jul 28, 2023

are the new changes backward compatible?

@auvipy auvipy self-requested a review July 28, 2023 04:15
@auvipy auvipy added this to the 5.3.x milestone Jul 29, 2023
@auvipy auvipy merged commit f34b1da into celery:main Jul 29, 2023
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.

2 participants