Skip to content

Swift: Diff-informed queries: phase 3 (non-trivial locations) #20082

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ module CleartextStorageDatabaseConfig implements DataFlow::ConfigSig {
node.asExpr().getType().getUnderlyingType() instanceof DictionaryType and
c.getAReadContent().(DataFlow::Content::TupleContent).getIndex() = 1
}

predicate observeDiffInformedIncrementalMode() { any() }

Location getASelectedSinkLocation(DataFlow::Node sink) {
exists(DataFlow::Node cleanSink | result = cleanSink.getLocation() |
cleanSink = sink.(DataFlow::PostUpdateNode).getPreUpdateNode()
or
not sink instanceof DataFlow::PostUpdateNode and
cleanSink = sink
)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ module CleartextStoragePreferencesConfig implements DataFlow::ConfigSig {
// make sources barriers so that we only report the closest instance
isSource(node)
}

predicate observeDiffInformedIncrementalMode() { any() }

Location getASelectedSinkLocation(DataFlow::Node sink) {
Copy link
Preview

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

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

The logic in getASelectedSinkLocation is duplicated across CleartextStoragePreferencesQuery.qll and CleartextStorageDatabaseQuery.qll. Consider extracting this common pattern into a shared utility predicate to improve maintainability.

Copilot uses AI. Check for mistakes.

exists(DataFlow::Node cleanSink | result = cleanSink.getLocation() |
cleanSink = sink.(DataFlow::PostUpdateNode).getPreUpdateNode()
or
not sink instanceof DataFlow::PostUpdateNode and
cleanSink = sink
)
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions swift/ql/lib/codeql/swift/security/InsecureTLSQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ module InsecureTlsConfig implements DataFlow::ConfigSig {
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
any(InsecureTlsExtensionsAdditionalFlowStep s).step(nodeFrom, nodeTo)
}

predicate observeDiffInformedIncrementalMode() {
none() // query selects some Swift nodes (e.g. "[post] self") that have location file://:0:0:0:0, which always fall outside the diff range.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you recall if there's any reason we don't give post-update nodes a Location (equal to that of the pre-update node)?

I may do a quick experiment with this (probably after your PR, to avoid complicating things).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it comes down to the use of UnknownLocation when an AstNode is synthesized.

}

module InsecureTlsFlow = TaintTracking::Global<InsecureTlsConfig>;
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ module UnsafeWebViewFetchConfig implements DataFlow::ConfigSig {
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
any(UnsafeWebViewFetchAdditionalFlowStep s).step(nodeFrom, nodeTo)
}

predicate observeDiffInformedIncrementalMode() {
none() // can't override location accurately because of secondary use in select.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the issue here? The only unusual thing I can see in that query is selecting from three possible alert messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This issue is the second flow call (UnsafeWebViewFetchFlow::flowToExpr) in the third disjunct: we can't include it in the location override because of monotonic recursion, but if we exclude it then the --check-diff-informed test fails, as it usually does with these cases of secondary flows. So we can't make these queries diff-informed, but their incrementality story will be handled separately using overlay-informed dataflow.

}

/**
Expand Down
Loading