CVE-2024-53908: Django Potential SQL injection in `HasKey(lhs, rhs)` on Oracle
Direct use of the HasKey JSON lookup on Oracle with untrusted data as the left-hand side value could allow SQL injection. An attacker could potentially run arbitrary SQL commands, leading to unauthorised access, data manipulation or information disclosure.
- Fixed in 2 months
- Paid in 2 months
- Disclosed after 2 months
Summary by the program
###CVE-2024-53908: Potential SQL injection in HasKey(lhs, rhs) on Oracle
Direct usage of the django.db.models.fields.json.HasKey lookup on Oracle is subject to SQL injection if untrusted data is used as a lhs value. Applications that use the jsonfield.has_key lookup through the __ syntax are unaffected.
Thanks to Seokchan Yoon for the report.
This issue has severity "high" according to the Django security policy.
The report
I've found a potential SQL Injection vulnerability and reported it to the Django team. You can find detailed information at the following link:
- https://www.djangoproject.com/weblog/2024/dec/04/security-releases/
- https://nvd.nist.gov/vuln/detail/CVE-2024-53908
Direct usage of the django.db.models.fields.json.HasKey lookup on Oracle is subject to SQL injection if untrusted data is used as a lhs value. Applications that use the jsonfield.has_key lookup through the __ syntax are unaffected.
Impact
This vulnerability could potentially allow an attacker to execute arbitrary SQL commands, leading to unauthorized access, data manipulation, or information disclosure. The issue affects the Django Framework, particularly when using the HasKey lookup on Oracle databases.
Context
Django ships a set of lookups for querying JSON data stored in JSONField columns. One of them is HasKey, implemented in django.db.models.fields.json.HasKey, which answers the question "does this JSON object contain this key?" by taking a left-hand side (the JSON column or expression) and a right-hand side (the key name).
The advisory covered here is CVE-2024-53908, a potential SQL injection in HasKey(lhs, rhs) that applies specifically to Oracle as the database backend. The report was credited to Seokchan Yoon. Django rated the issue severity "high" according to its security policy.
The crucial distinction in the advisory is between two ways of reaching the lookup:
- Direct usage of
django.db.models.fields.json.HasKey, where untrusted data is used as thelhsvalue. This is the vulnerable path. - Usage of the
jsonfield.has_keylookup through the__syntax (for example, filtering with a double-underscore lookup on aJSONField). Applications that query this way are unaffected.
Setup
The report does not describe a test environment, accounts, roles, tooling or specific Django or Oracle versions. What it does establish as preconditions, from the advisory text, are:
- The application runs on Oracle as its database backend.
- The application constructs a query using
django.db.models.fields.json.HasKeydirectly, rather than through the__lookup syntax. - Untrusted input reaches the
lhsargument of that lookup.
If any of these does not hold, the described issue does not apply. In particular, the ordinary jsonfield.has_key path via __ is explicitly out of scope.
Finding it
The researcher identified that the HasKey lookup, when used directly with an untrusted value as its left-hand side on Oracle, is subject to SQL injection. The report does not walk through the discovery process, the code reading, or the experiments that led to the conclusion; it states the finding and points to the Django security release announcement and the NVD entry for CVE-2024-53908 for detail.
What makes the finding notable is the narrowness of the condition. The same lookup reached through the documented __ syntax is safe, so the bug is not in how Django parses jsonfield.has_key filters in general, but in what happens when a caller builds HasKey directly and lets untrusted data occupy the lhs position on Oracle.
Exploitation
The report does not include a proof-of-concept request, payload, SQL fragment, stack trace or response. It describes the exploitation path at the level of the vulnerable construction and its consequence, not as a sequence of reproducible steps. What can be said from the report is:
- An application on Oracle builds a query using
django.db.models.fields.json.HasKeydirectly. - Untrusted data is supplied as the
lhsvalue of that lookup. - Because that value is not safely handled on Oracle, the attacker's input can influence the SQL that is executed.
- The result, per the impact section, is the potential execution of arbitrary SQL commands.
The report gives no concrete input that triggers the behaviour.
Root cause
The report attributes the flaw to direct usage of django.db.models.fields.json.HasKey on Oracle when untrusted data is used as the lhs value. In other words, the lhs of the lookup is the injection point, and the Oracle backend is where the unsafe handling manifests. The __ syntax path for jsonfield.has_key does not expose the same behaviour, which indicates the problem is tied to how a directly constructed HasKey expression is compiled for Oracle rather than to the lookup's normal query interface.
The report does not include the underlying code change or a line-level explanation of why the lhs is not properly parameterised or quoted on Oracle, so the precise mechanism is not stated. The report does not describe why existing defences did not stop it.
Impact
As stated in the report, the vulnerability could potentially allow an attacker to execute arbitrary SQL commands, leading to unauthorised access, data manipulation, or information disclosure. The affected component is the Django framework, and the exposure is limited to deployments that use the HasKey lookup directly on Oracle databases with untrusted data as the lhs value. Applications that only use jsonfield.has_key through the __ syntax are unaffected. The report uses hedged language ("could potentially"), and no specific exploitation against a live application is demonstrated.
Fix
It refers readers to the Django security release announcement at https://www.djangoproject.com/weblog/2024/dec/04/security-releases/ and to the NVD entry for CVE-2024-53908 for the details of the resolution. What the advisory does make clear is the boundary of the fix's scope: the direct HasKey usage on Oracle is the thing that needed correcting, while the __ syntax path was already safe.
Variants to test
These follow from the conditions the report sets out; the report itself does not list variants.
- Direct
HasKeywith attacker-controlledlhson Oracle. Look for application code that imports and constructsdjango.db.models.fields.json.HasKeyitself rather than filtering through__. A positive result is input in thelhsposition changing the generated SQL or producing database errors that reveal injected syntax. - Other direct JSON lookups on Oracle. The report only names
HasKey, but any codebase that builds JSON lookups by hand is worth reviewing for the same pattern of untrusted data in an expression position. A positive result is the same kind of SQL influence on a different lookup. - Confirming the safe path. Reproduce the same query through
jsonfield.has_keywith the__syntax and check that the input is handled safely. A positive result here would contradict the advisory and is not expected.
Hunting notes
The signal to look for during review is application code that reaches past the ORM's lookup syntax and instantiates django.db.models.fields.json.HasKey directly, especially where a request parameter, header or other user-controlled value is passed as the lhs. This pattern is most likely in code that builds query expressions dynamically, for example generic filtering layers or reporting features that assemble lookups from configuration or user input. The database backend matters: the report ties the issue to Oracle, so a Django deployment on another backend is not the target described here.
On impact: the report establishes severity through the Django security policy ("high") and through the potential for arbitrary SQL execution, unauthorised access, data manipulation and information disclosure. It does not present a working exploit or a measured result against a live system.
What happened, in plain words
Django is a popular toolkit for building websites with the Python programming language. One of its features lets a website store structured data in a database column called a JSONField. JSON is a simple text format for data, made of keys (names) and values, a bit like a labelled filing cabinet: each drawer has a name on it, and inside is some content.
Django provides small helper tools, called lookups, for asking questions about that stored data. One of them is called HasKey, and it answers a single question: does this JSON object contain this particular key? You give it two things: the left-hand side (the JSON column or expression to look in) and the right-hand side (the name of the key you are looking for).
The security problem described here is CVE-2024-53908. A CVE is a public catalogue number given to a known security flaw so people can look it up. This one is a potential SQL injection in HasKey(lhs, rhs) that only applies when the database behind the website is Oracle. SQL is the language used to talk to databases, and SQL injection means sneaking your own SQL commands into a place where the program expected only plain data, the way someone might write extra instructions on a form where only a name was expected.
The flaw was reported to the Django team and handled through the Internet Bug Bounty programme on HackerOne. A bug bounty programme is a scheme where organisations pay people for finding and reporting security problems responsibly. The report is credited to Seokchan Yoon. Django rated the issue severity "high" according to its security policy.
The most important thing to understand is the difference between two ways of reaching this lookup:
- Direct usage of
django.db.models.fields.json.HasKey, where untrusted data is used as thelhsvalue. This is the vulnerable path. "Untrusted data" means anything a user can type or send, such as a search box entry or a value in a web address. - Usage of the
jsonfield.has_keylookup through the__syntax, for example filtering with a double-underscore lookup on aJSONField. Applications that query this way are unaffected.
So the same question ("does this JSON contain this key?") can be asked in two ways, and only one of them is dangerous.
Context
Django ships a set of lookups for querying JSON data stored in JSONField columns. A lookup is a small built-in helper that turns a question about data into part of a database query. One of them is HasKey, implemented in django.db.models.fields.json.HasKey, which answers the question "does this JSON object contain this key?" by taking a left-hand side (the JSON column or expression) and a right-hand side (the key name).
The advisory covered here is CVE-2024-53908, a potential SQL injection in HasKey(lhs, rhs) that applies specifically to Oracle as the database backend. A database backend is the specific database software a website uses underneath; Django can work with several, and Oracle is one of them. The report was credited to Seokchan Yoon. The report was disclosed on 2025-02-07.
The crucial distinction in the advisory is between two ways of reaching the lookup:
- This is the vulnerable path.
To picture the difference: the __ syntax is like ordering from a fixed menu, where the kitchen controls how your order is prepared. Direct usage is like walking into the kitchen and handing the chef a note you wrote yourself. Usually that is fine, but if the note is passed along without being checked, someone can write something the chef did not expect.
Setup
The report does not describe a test environment, accounts, roles, tooling or specific Django or Oracle versions. What it does establish as preconditions, from the advisory text, are:
- The application runs on Oracle as its database backend.
- The application constructs a query using
django.db.models.fields.json.HasKeydirectly, rather than through the__lookup syntax. - Untrusted input reaches the
lhsargument of that lookup.
If any of these does not hold, the described issue does not apply. In particular, the ordinary jsonfield.has_key path via __ is explicitly out of scope.
Think of these three conditions as a combination lock: all three dials must line up before the problem exists. A website on a different database, or one that only uses the __ syntax, or one that never lets user input reach the lhs, is not exposed in the way described.
Finding it
The researcher identified that the HasKey lookup, when used directly with an untrusted value as its left-hand side on Oracle, is subject to SQL injection. The report does not walk through the discovery process, the code reading, or the experiments that led to the conclusion; it states the finding and points to the Django security release announcement and the NVD entry for CVE-2024-53908 for detail. NVD is the National Vulnerability Database, a public reference site that records known vulnerabilities.
What makes the finding notable is the narrowness of the condition. The same lookup reached through the documented __ syntax is safe, so the bug is not in how Django parses jsonfield.has_key filters in general, but in what happens when a caller builds HasKey directly and lets untrusted data occupy the lhs position on Oracle.
A useful comparison is a building with two doors. The front door has a guard who checks everyone's bag. The side door, used only by staff who are expected to know the rules, has no guard. The flaw is not that the building is insecure in general; it is that the side door can be reached by someone who should have gone through the front.
Exploitation
The report does not include a proof-of-concept request, payload, SQL fragment, stack trace or response. A proof of concept is a small demonstration that shows a flaw is real. It describes the exploitation path at the level of the vulnerable construction and its consequence, not as a sequence of reproducible steps. What can be said from the report is:
- An application on Oracle builds a query using
django.db.models.fields.json.HasKeydirectly. - Untrusted data is supplied as the
lhsvalue of that lookup. - Because that value is not safely handled on Oracle, the attacker's input can influence the SQL that is executed.
- The result, per the impact section, is the potential execution of arbitrary SQL commands.
The report gives no concrete input that triggers the behaviour.
In everyday terms: the report tells us that a particular door can be forced, and what could happen if it is, but it does not hand us a photograph of the forced door or a recording of someone doing it. That is why the language stays cautious ("could potentially") rather than claiming a demonstrated break-in.
Root cause
The report attributes the flaw to direct usage of django.db.models.fields.json.HasKey on Oracle when untrusted data is used as the lhs value. In other words, the lhs of the lookup is the injection point, and the Oracle backend is where the unsafe handling manifests. The __ syntax path for jsonfield.has_key does not expose the same behaviour, which indicates the problem is tied to how a directly constructed HasKey expression is compiled for Oracle rather than to the lookup's normal query interface. "Compiled" here means the step where Django turns the lookup into the actual SQL text sent to the database.
The report does not include the underlying code change or a line-level explanation of why the lhs is not properly parameterised or quoted on Oracle, so the precise mechanism is not stated. Parameterising means sending data to the database separately from the command, so the database treats it purely as a value and never as instructions; quoting means wrapping a value in quotes so it cannot break out of its slot. The report does not describe why existing defences did not stop it.
Impact
As stated in the report, the vulnerability could potentially allow an attacker to execute arbitrary SQL commands, leading to unauthorised access, data manipulation, or information disclosure. In plain words: unauthorised access means seeing or doing things you should not be allowed to; data manipulation means changing or deleting records; information disclosure means reading data that was meant to stay private. The affected component is the Django framework, and the exposure is limited to deployments that use the HasKey lookup directly on Oracle databases with untrusted data as the lhs value. Applications that only use jsonfield.has_key through the __ syntax are unaffected. The report uses hedged language ("could potentially"), and no specific exploitation against a live application is demonstrated.
Fix
A patch is the code change that repairs the flaw. It refers readers to the Django security release announcement at https://www.djangoproject.com/weblog/2024/dec/04/security-releases/ and to the NVD entry for CVE-2024-53908 for the details of the resolution. What the advisory does make clear is the boundary of the fix's scope: the direct HasKey usage on Oracle is the thing that needed correcting, while the __ syntax path was already safe.
Variants to test
These follow from the conditions the report sets out; the report itself does not list variants.
- Direct
HasKeywith attacker-controlledlhson Oracle. Look for application code that imports and constructsdjango.db.models.fields.json.HasKeyitself rather than filtering through__. A positive result is input in thelhsposition changing the generated SQL or producing database errors that reveal injected syntax. - Other direct JSON lookups on Oracle. The report only names
HasKey, but any codebase that builds JSON lookups by hand is worth reviewing for the same pattern of untrusted data in an expression position. A positive result is the same kind of SQL influence on a different lookup. - Confirming the safe path. Reproduce the same query through
jsonfield.has_keywith the__syntax and check that the input is handled safely. A positive result here would contradict the advisory and is not expected.
Hunting notes
The signal to look for during review is application code that reaches past the ORM's lookup syntax and instantiates django.db.models.fields.json.HasKey directly, especially where a request parameter, header or other user-controlled value is passed as the lhs. An ORM, or object-relational mapper, is the part of Django that lets programmers write database queries in Python instead of raw SQL. A request parameter is a value sent by the browser, for example in a web address or a form; a header is extra information the browser attaches to each request, such as the type of content it expects. This pattern is most likely in code that builds query expressions dynamically, for example generic filtering layers or reporting features that assemble lookups from configuration or user input. The database backend matters: the report ties the issue to Oracle, so a Django deployment on another backend is not the target described here.
On impact: the report establishes severity through the Django security policy ("high") and through the potential for arbitrary SQL execution, unauthorised access, data manipulation and information disclosure. It does not present a working exploit or a measured result against a live system.
Glossary
- Django: a toolkit (framework) for building websites in Python.
- Python: a popular programming language.
- JSON: a simple text format for structured data, made of keys and values.
- JSONField: a Django database column type that stores JSON data.
- Lookup: a built-in helper that turns a question about data into part of a database query.
- HasKey: a Django lookup that asks whether a JSON object contains a given key.
- lhs (left-hand side): the value or expression on the left of a lookup, here the JSON column or expression being searched.
- rhs (right-hand side): the value on the right of a lookup, here the key name being searched for.
- SQL: the language used to send commands to a database.
- SQL injection: tricking a program into treating user input as SQL commands rather than plain data.
- CVE: a public catalogue number for a known security vulnerability.
- NVD: the National Vulnerability Database, a public reference site for vulnerabilities.
- Bug bounty programme: a scheme where organisations reward people for responsibly reporting security flaws.
- HackerOne: a platform that hosts bug bounty programmes.
- Internet Bug Bounty: the programme through which this report was handled.
- Severity: a rating of how serious a flaw is, here "high" under Django's security policy.
- Database backend: the specific database software a website uses, such as Oracle.
- Oracle: a commercial database system.
- Untrusted data: any input a user can supply, such as form fields or web address values.
- Direct usage: calling a lookup such as
HasKeyin code yourself, instead of going through Django's__filter syntax. __syntax: Django's double-underscore notation for expressing lookups inside a filter, for example on aJSONField.- ORM (object-relational mapper): the part of Django that lets you write database queries in Python.
- Compiled: turned from a Python lookup into the actual SQL text sent to the database.
- Parameterised: sent to the database separately from the command, so it is treated only as a value.
- Quoting: wrapping a value in quotes so it cannot break out of its slot in a query.
- Patch: the code change that repairs a flaw.
- Proof of concept: a small demonstration showing a flaw is real.
- Request parameter: a value sent by the browser, for example in a web address or form.
- Header: extra information the browser attaches to a request.
- Unauthorised access: seeing or doing things you are not permitted to.
- Data manipulation: changing or deleting records without permission.
- Information disclosure: reading data that was meant to stay private.