-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Java: add Android database taint and SQL injection sinks #4336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| // query(boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit) | ||
| // query(boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit, CancellationSignal cancellationSignal) | ||
| // query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit) | ||
| // query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy) | ||
| this.getName() = "query" and | ||
| (if this.getParameter(0).getType() instanceof TypeString then result = 2 else result = 3) | ||
| ( | ||
| if this.getParameter(0).getType() instanceof TypeString | ||
| then result = [2, 4, 5, 6, 7] | ||
| else result = [3, 5, 6, 7, 8] | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking a quick look at the android SQLite surce code, it looks like all of these arguments besides selectionArgs are potential query injection sinks, rather than just the ones listed. Though maybe it's so rare for the tables/columns to be tainted that it isn't worth the effort.
| private class QueryBuilderQueryMethod extends SQLiteRunner { | ||
| QueryBuilderQueryMethod() { | ||
| // query(SQLiteDatabase db, String[] projectionIn, String selection, String[] selectionArgs, String groupBy, String having, String sortOrder) | ||
| // query(SQLiteDatabase db, String[] projectionIn, String selection, String[] selectionArgs, String groupBy, String having, String sortOrder, String limit) | ||
| // query(SQLiteDatabase db, String[] projectionIn, String selection, String[] selectionArgs, String groupBy, String having, String sortOrder, String limit, CancellationSignal cancellationSignal) | ||
| this.getDeclaringType().getASourceSupertype*() instanceof TypeSQLiteQueryBuilder and | ||
| this.hasName("query") | ||
| } | ||
|
|
||
| override int sqlIndex() { result = [-1, 3, 5, 6, 7, 8] } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These indicies look off by one - the selection arg is at index 2
joefarebrother
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
8971092


This pull request adds taint steps and SQL injection sinks for the following classes of the Android database library:
DatabaseUtils,SQLiteDatabase,SQLiteQueryBuilder, and part ofContentProvider/Resolver.The SQLiteQueryBuilder class mostly performs unverified string concatenation for any parts of the SQL query string. This can be mitigated by setting its strictness flags which harden the query builder against SQL injection attempts. This pull request does not model the strictness flags and can therefore lead to false positives. We can improve that in the future if the false positive rate is deemed too high.