Repository navigation
Conversation
1 task done
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add CodeQL query for credential and data exposure
[NEW QUERY] Swift: credential and sensitive data exposure (Oct 31, 2026
swift/credential-and-data-exposure)
There was a problem hiding this comment.
🟡 Changes recommended
The query can miss unsafe writes and retained secrets because protection checks are not write-specific and clearing logic incorrectly accepts arbitrary zero-argument calls and partial buffer resets.
4 open issues
What changed in this PR
Adds swift/credential-and-data-exposure, a low-precision security audit query addressing six credential and sensitive-data exposure patterns from issue #256, along with the repository’s first Swift custom packs.
Changes:
- Detects pasteboard exposure, credential-derived tokens, missing snapshot protection, weak keychain accessibility, sensitive caching, and retained sensitive values.
- Adds query documentation and positive/negative Swift fixtures with expected results.
- Excludes Swift tests from discovery on the Ubuntu test runner.
| File | Description |
|---|---|
languages/swift/custom/test/qlpack.yml |
Defines the Swift test pack. |
languages/swift/custom/test/CredentialAndDataExposure/test.swift |
Adds fixtures for all six detection patterns. |
languages/swift/custom/test/CredentialAndDataExposure/keychain_accessible.swift |
Adds separate keychain accessibility cases. |
languages/swift/custom/test/CredentialAndDataExposure/CredentialAndDataExposure.qlref |
Connects the query to inline expectations. |
languages/swift/custom/test/CredentialAndDataExposure/CredentialAndDataExposure.expected |
Records expected query results. |
languages/swift/custom/src/qlpack.yml |
Defines the Swift query pack. |
languages/swift/custom/src/CredentialAndDataExposure/CredentialAndDataExposure.ql |
Implements the six detection heuristics. |
languages/swift/custom/src/CredentialAndDataExposure/CredentialAndDataExposure.md |
Documents coverage, recommendations, and examples. |
.github/workflows/codeql-qlt-unit-tests.yml |
Skips Swift test discovery on Ubuntu. |
Review effort: Balanced
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
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.


📝 Query Information
swift/credential-and-data-exposure@security-severity 5.5,@precision low)🎯 Description
AI Scan found 7 Swift credential and data exposure findings that the default CodeQL scan does not report, and no existing Swift query covers them. This PR adds one query for the six patterns behind those findings, along with the first Swift custom packs in this repo.
What This Query Detects
SensitiveExpr, or from names matchingdecrypt|plaintext|cleartext, intoUIPasteboardsetters orsetValue/setData/addItems/setItems/setObjects. The write is safe if the same callable references.localOnlyor.expirationDate.*encrypt*call (notdecrypt) whose result is stored in a variable or property namedtoken,sessionorcookie.UIApplicationDelegate(including its extensions) does not implementapplicationDidEnterBackground(_:)orapplicationWillResignActive(_:), the app has no scene-delegate or notification equivalent, and it declares a sensitiveUITextField/UITextView.SecItemAddin a file that never referenceskSecAttrAccessibleorkSecAttrAccessControl, plus any use ofkSecAttrAccessibleAlways*..returnCacheDataElseLoador.returnCacheDataDontLoadinside a function that touches aSensitiveExpror a credential-like string literal.String/Dataproperty of a class is assigned, but never set tonil,""or an empty value, and neverremoveAll'd.Notes:
SensitiveExprsheuristic treats any name containingcryptas non-sensitive. That misses the Swift.nVdecryptedValcase, so decrypted-plaintext names are added as pasteboard sources.UnknownLocation, such as compiler-generated property accessors, are dropped.swift/hardcoded-key. iGoat-Swift alert 56 relies on storyboard-only fields, so the app delegate alert covers it only indirectly.Example Vulnerable Code
Example Safe Code
🧪 Testing
The tests use inline expectations (
// $ Alert[swift/credential-and-data-exposure]). CodeQL 2.27.2 ships only a macOS Swift extractor, so the test database was built with the v2.15.5 Linux extractor and then upgraded withcodeql database upgrade.codeql test run --reuse-datasetpasses on that database. The.expectedfile may need a--learnon macOS. The Swift files are compiled one at a time during test extraction, sokeychain_accessible.swifthas its own stubs. It is also a separate file because the keychain check works per file..github/workflows/codeql-qlt-unit-tests.ymlnow skipsswiftduring test discovery on the ubuntu runner, likeqlandactions.📋 Checklist
.mdand.qhelp):.mdonly, no.qhelp🔗 References
swift/cleartext-storage-preferences,swift/hardcoded-keyNote: This query was developed using Test-Driven Development methodology.