Repository navigation
Conversation
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Overbroad sanitization barriers can suppress unsafe pointer-access findings by accepting partial bounds checks, reassigned variables, tainted clamp bounds, and arbitrary size-named properties.
4 open issues
What changed in this PR
Adds swift/untrusted-pointer-offset to the custom CodeQL queries, targeting attacker-controlled offsets, indices, and lengths in unsafe Swift pointer operations.
Changes:
- Models pointer-operation sinks, URL-derived taint, and bounds-check barriers.
- Adds Swift source/test packs, query documentation, and positive and negative fixtures.
- Excludes Swift tests from the Ubuntu workflow; macOS execution and expected results remain pending.
| File | Description |
|---|---|
languages/swift/custom/test/UntrustedPointerOffset/UntrustedPointerOffset.swift |
Adds deep-link, pointer-operation, and bounds-check fixtures. |
languages/swift/custom/test/UntrustedPointerOffset/UntrustedPointerOffset.qlref |
Connects fixtures to the query and inline expectations processor. |
languages/swift/custom/test/qlpack.yml |
Defines the Swift test pack. |
languages/swift/custom/src/UntrustedPointerOffset/UntrustedPointerOffset.ql |
Implements taint tracking, pointer sinks, and barriers. |
languages/swift/custom/src/UntrustedPointerOffset/UntrustedPointerOffset.md |
Documents risks, recommendations, and examples. |
languages/swift/custom/src/qlpack.yml |
Defines the Swift query pack. |
.github/workflows/codeql-qlt-unit-tests.yml |
Skips Swift tests on the Linux runner. |
Review effort: Balanced
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
|
@copilot A rescan of the synthetic corpus found additional medium and low severity findings that fit this gap. Please re-run your analysis against each finding below, confirm whether the proposed change covers each scenario, and extend it where it does not. Keep each change minimal with a positive and a negative regression test, keep every existing test passing, and do not broaden scope. The same findings are listed in the matching comment on issue #100. Linked findings
HandlingCreate a new CodeQL query. No existing query covers these patterns (most findings are gap type Patterns
Finding details1. iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Extensions/Data+Extension.swift:11 (CWE-125, medium)
2. iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Extensions/NSString+Extension.swift:10 (CWE-125, medium)
Please continue on this pull request. |
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Added a dedicated |

📝 Query Information
swift/untrusted-pointer-offset(languages/swift/custom/src/UntrustedPointerOffset/UntrustedPointerOffset.ql)@security-severity 8.1,@precision medium)🎯 Description
Fills the gap where no Swift query covers attacker-controlled offsets used with unsafe pointers. Default setup missed an OVIA deep-link handler that adds a signed
offsetfrom the URL to a pointer and also uses it to compute a copy length.What This Query Detects
The taint source is the stock Swift
FlowSource. A sink is any argument that sets the offset, index or length of an unsafe pointer access:+/-/+=/-=(the non-pointer operand)Unsafe[Mutable][Raw]Pointer,AutoreleasingUnsafeMutablePointeradvanced(by:),load(fromByteOffset:as:),loadUnaligned(fromByteOffset:as:)Data(bytes:count:),Data(bytesNoCopy:count:deallocator:),NSData(bytes[NoCopy]:length:…),Unsafe*BufferPointer(start:count:)Barriers:
contains(_:)and~=all count. One-sided checks still alert, because negativeIntoffsets are the attack.min(max(…))/max(min(…))..count,.capacity,.startIndex,.endIndex. The size of untrusted data is not an attacker-chosen offset.New taint models, needed for the URL query-parameter pattern and scoped to this query:
URLComponents/NSURLComponentsinitializers and fieldsURLQueryItemfieldsSequence.first(where:), where taint on the whole collection flows to the returned elementExample Vulnerable Code
Example Safe Code
🧪 Testing
UntrustedPointerOffset.swiftuses only the standard library plus stubs. It type-checks withswiftc6.4, andswiftc -dump-astwas used to check how the AST is resolved (for example,&data + offsetresolves toStrideable.+whereSelf: _Pointer).Positive cases:
advanced(by:), pointer subscript,ptr - i,ptr += ibaseAddress! + iused inside a closureNegative cases:
ifcheckguardcheckcontainsused in anif letcondition📋 Checklist
.mdand.qhelp)Other changes:
languages/swift/custom/{src,test}packs.codeql-qlt-unit-tests.ymlnow skipsswiftduring language discovery, sinceubuntu-latestcannot extract Swift.Known limitations:
🔗 References
saveroute)codeql/swift-allCustomUrlSchemes.qll,Url.qll, and theswift/uncontrolled-format-stringquery.Note: This query was developed using Test-Driven Development methodology.