Repository navigation
Conversation
1 task done
… models Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add data extension models for path traversal in Swift
[NEW DATA EXTENSION] Swift CWE-22: QL models for deep-link query parameters into file paths (swift/path-injection-extended)
Oct 16, 2026
There was a problem hiding this comment.
🔵 Needs a closer look
The new Swift models and lifecycle-property flow remain unverified against an extracted Swift database, requiring macOS tests to confirm source-to-sink flow and both positive and negative expectations.
No open issues 🎉
What changed in this PR
Adds swift/path-injection-extended to address the deep-link path-traversal detection gap described in #104. It uses QL models rather than YAML data extensions, which Swift does not support.
Changes:
- Models URL query-parameter parsing and stored view-controller properties to extend path-injection tracking.
- Adds Swift query/test packs and positive and negative regression cases.
- Skips Swift tests in the Linux unit-test workflow; end-to-end validation remains pending on macOS.
| File | Description |
|---|---|
languages/swift/custom/test/qlpack.yml |
Defines the Swift test pack and source-pack dependency. |
languages/swift/custom/test/PathInjectionExtended/PathInjectionExtendedTest.ql |
Checks path-injection results against inline expectations. |
languages/swift/custom/test/PathInjectionExtended/PathInjectionExtendedTest.expected |
Adds an empty baseline for inline expectation checks. |
languages/swift/custom/test/PathInjectionExtended/deeplink.swift |
Adds deep-link flow cases and safe constant-path counterparts. |
languages/swift/custom/src/qlpack.yml |
Defines the custom Swift query pack. |
languages/swift/custom/src/PathInjectionExtended/PathInjectionModels.qll |
Adds parsing summaries, field taint inheritance, and view-controller flow modeling. |
languages/swift/custom/src/PathInjectionExtended/PathInjectionExtended.ql |
Wraps the stock path-injection analysis with the additional models. |
.github/workflows/codeql-qlt-unit-tests.yml |
Excludes Swift extraction from the Linux test runner. |
Review effort: Balanced
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Data Extension Information
languages/swift/custom/src/PathInjectionExtended/PathInjectionModels.qll, wrapped byPathInjectionExtended.ql(swift/path-injection-extended).SummaryModelCsv), taint-inheriting fields (viaTaintInheritingContent), and one extra flow step for path injection only (PathInjectionAdditionalFlowStep)URLComponents,NSURLComponents,URLQueryItem,NSURLQueryItem), Swift stdlib (Sequence), UIKit (UIViewController)Sequence.first(where:), properties stored onUIViewControllersubclasses🎯 Description
What This Data Extension Models
AI Scan found a deep-link "save" route (OversecuredVulnerableiOSApp) that writes attacker data to
Documents/<name>. CodeQL default setup did not report it. The issue guessed the Documents URL helper was the missing link. It is not: the helper is app code,URL.appendingPathComponentis already modeled, andData.write(to:options:)is already a sink. The flow actually breaks in three places:URLComponents/NSURLComponentsinitializersinit(url:resolvingAgainstBaseURL:)andinit(string:):Argument[0]→ReturnValue.OptionalSome(taint)queryItems,name,valuehave no taint inheritanceTaintInheritingContentfor all fields ofURLComponents,NSURLComponents,URLQueryItem,NSURLQueryItemSequence.first(where:)only carries taint from collection elements, so a taintedqueryItemsarray loses itArgument[-1]→ReturnValue(taint)viewDidAppear(_:), which UIKit calls, not app codeUIViewControllersubclass flows toself.<prop>readsThe view-controller step only applies to path injection. It can over-report: any
selfread is flagged once any tainted value is assigned to the property, even if it was read before the write.Swift has no extensible predicates in
codeql/swift-all, so a.model.ymlfile cannot work. These QL models only apply to queries that import them, which is why this adds a wrapper query rather than relying on the stockswift/path-injection.The qlt unit-test workflow now skips Swift explicitly: the Swift extractor only runs on macOS, so Linux runners cannot extract Swift tests.
Threat Model
remote. The source is the existing
UIApplication.LaunchOptionsKey.url/application(_:open:options:)custom URL scheme source.Example Vulnerable Code
Example Safe Code
📦 Extension Details
Extension YAML
Not applicable for Swift. These are the equivalent rows in
UrlComponentsSummaries:Access Path Explanation
ReturnValue.OptionalSome. This matches the stockURL.init(string:)rows.first(where:)uses plainReturnValue, alongside the stockCollectionElementvalue row. Swift dataflow already steps through?.,!, andif leton a tainted optional.getEnclosingDecl().asNominalTypeDecl().getFullName(), so properties declared in extensions are covered too.x.<prop> = vto aMemberRefExprread of<prop>whose base is theselfparameter. Assignment targets are excluded. The property's type must haveUIViewControlleras a base type (transitively).🧪 Testing
Swift tests cannot be extracted on Linux, so nothing has run end to end. Someone on macOS needs to run
codeql test run languages/swift/custom/test/PathInjectionExtended/.summaryModelon an empty dataset)codeql database createorcodeql test extract)codeql query run --additional-packs=<model-pack-dir>)codeql test run --additional-packs=<model-pack-dir>)deeplink.swift, not yet rundeeplink.swift, not yet runThe test uses an
InlineExpectationsTestquery with an empty.expectedfile, so the expectations live inline in the Swift file.📋 Checklist
languages/[language]/custom/src/)qlpack.ymlincludesdataExtensionsconfiguration (not applicable to Swift).qll)🔗 References
swift/path-injection; source models incodeql/swift/frameworks/StandardLibrary/CustomUrlSchemes.qllNote: This data extension was developed following CodeQL Models as Data best practices.