Skip to content

Java: add Android database taint and SQL injection sinks#4336

Merged
aibaars merged 10 commits intogithub:mainfrom
aibaars:android-database
Oct 6, 2020
Merged

Java: add Android database taint and SQL injection sinks#4336
aibaars merged 10 commits intogithub:mainfrom
aibaars:android-database

Conversation

@aibaars
Copy link
Contributor

@aibaars aibaars commented Sep 23, 2020

This pull request adds taint steps and SQL injection sinks for the following classes of the Android database library: DatabaseUtils, SQLiteDatabase, SQLiteQueryBuilder, and part of ContentProvider/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.

@github-actions github-actions bot added the Java label Sep 23, 2020
@aibaars aibaars marked this pull request as ready for review September 30, 2020 11:10
@aibaars aibaars requested a review from a team as a code owner September 30, 2020 11:10
Comment on lines 48 to 57
// 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]
)
Copy link
Contributor

@joefarebrother joefarebrother Sep 30, 2020

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.

Comment on lines 165 to 175
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] }
}
Copy link
Contributor

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
joefarebrother previously approved these changes Sep 30, 2020
Copy link
Contributor

@joefarebrother joefarebrother left a comment

Choose a reason for hiding this comment

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

Looks good

aschackmull
aschackmull previously approved these changes Oct 6, 2020
@aibaars aibaars dismissed stale reviews from aschackmull and joefarebrother via 8971092 October 6, 2020 08:48
@aibaars aibaars merged commit 3c41548 into github:main Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants