|
| 1 | +--- |
| 2 | +gem: activerecord |
| 3 | +cve: 2023-22794 |
| 4 | +ghsa: hq7p-j377-6v63 |
| 5 | +url: https://github.com/rails/rails/releases/tag/v7.0.4.1 |
| 6 | +title: SQL Injection Vulnerability via ActiveRecord comments |
| 7 | +date: 2023-01-18 |
| 8 | +description: |- |
| 9 | + There is a possible vulnerability in ActiveRecord related to the |
| 10 | + sanitization of comments. This vulnerability has been assigned the CVE |
| 11 | + identifier CVE-2023-22794. |
| 12 | +
|
| 13 | + Versions Affected: >= 6.0.0 |
| 14 | + Not affected: < 6.0.0 |
| 15 | + Fixed Versions: 6.0.6.1, 6.1.7.1, 7.0.4.1 |
| 16 | +
|
| 17 | + # Impact |
| 18 | +
|
| 19 | + Previously the implementation of escaping for comments was insufficient for |
| 20 | +
|
| 21 | + If malicious user input is passed to either the annotate query method, the |
| 22 | + optimizer_hints query method, or through the QueryLogs interface which |
| 23 | + automatically adds annotations, it may be sent to the database with |
| 24 | + insufficient sanitization and be able to inject SQL outside of the comment. |
| 25 | +
|
| 26 | + In most cases these interfaces won’t be used with user input and users |
| 27 | + should avoid doing so. |
| 28 | +
|
| 29 | + Example vulnerable code: |
| 30 | + ``` |
| 31 | + Post.where(id: 1).annotate("#{params[:user_input]}") |
| 32 | +
|
| 33 | + Post.where(id: 1).optimizer_hints("#{params[:user_input]}") |
| 34 | + ``` |
| 35 | +
|
| 36 | + Example vulnerable QueryLogs configuration (the default configuration is not |
| 37 | + vulnerable): |
| 38 | + ``` |
| 39 | + config.active_record.query_log_tags = [ |
| 40 | + { |
| 41 | + something: -> { <some value including user input> } |
| 42 | + } |
| 43 | + ] |
| 44 | + ``` |
| 45 | + All users running an affected release should either upgrade or use one of the |
| 46 | + workarounds immediately. |
| 47 | +
|
| 48 | + # Workarounds |
| 49 | +
|
| 50 | + Avoid passing user input to annotate and avoid using QueryLogs configuration |
| 51 | + which can include user input. |
| 52 | +unaffected_versions: |
| 53 | +- "< 6.0.0" |
| 54 | +patched_versions: |
| 55 | +- "~> 6.0.6, >= 6.0.6.1" |
| 56 | +- "~> 6.1.7, >= 6.1.7.1" |
| 57 | +- ">= 7.0.4.1" |
| 58 | +related: |
| 59 | + url: |
| 60 | + - https://github.com/rails/rails/commit/d7aba06953f9fa789c411676b941d20df8ef73de |
0 commit comments