Skip to content

Swift: Add some summary queries. #10903

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

Merged
merged 5 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions swift/ql/src/queries/Summary/FlowSources.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @name Flow Sources
* @description List all flow sources found in the database. Flow sources
* indicate data that originates from an untrusted source, such
* as as untrusted remote data.
* @kind problem
* @problem.severity info
* @id swift/summary/flow-sources
* @tags summary
*/

import swift
import codeql.swift.dataflow.FlowSources

from RemoteFlowSource s
select s, "Flow source: " + s.getSourceType()
17 changes: 17 additions & 0 deletions swift/ql/src/queries/Summary/SensitiveExprs.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @name Sensitive Expressions
* @description List all sensitive expressions found in the database.
* Sensitive expressions are expressions that have been
* identified as potentially containing data that should not be
* leaked to an attacker.
* @kind problem
* @problem.severity info
* @id swift/summary/sensitive-expressions
* @tags summary
*/

import swift
import codeql.swift.security.SensitiveExprs

from SensitiveExpr e
select e, "Sensitive expression: " + e.getSensitiveType()
25 changes: 25 additions & 0 deletions swift/ql/src/queries/Summary/SummaryStats.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @name Summary statistics
* @description A table of summary statistics about a database.
* @kind table
* @id swift/summary/summary-statistics
* @tags summary
*/

import swift
import codeql.swift.dataflow.FlowSources
import codeql.swift.security.SensitiveExprs

predicate statistic(string what, int value) {
what = "Files" and value = count(File f)
or
what = "Expressions" and value = count(Expr e | not e.getFile() instanceof UnknownFile)
or
what = "Remote flow sources" and value = count(RemoteFlowSource s)
or
what = "Sensitive expressions" and value = count(SensitiveExpr e)
}

from string what, int value
where statistic(what, value)
select what, value