Skip to content

[Query Create]: CWE-200, CWE-316, CWE-522, CWE-922 MEDIUM - Swift: new query for credential and sensitive data exposure #256

Open

Description

@felickz

Target Language

swift

Query Name (Optional)

CredentialAndDataExposure

Query Type

Security

Query Description

AI Scan reported 7 medium and low-severity CWE-200, CWE-316, CWE-522, CWE-922 (credential and data exposure) finding(s) in Swift public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: missing-query, query-absent. Existing queries considered: none.

Why CodeQL appears to have missed these (unverified until reproduced with a test database):

  • No installed query covers sensitive values copied to the global pasteboard without expiration or local-only options.
  • Session token is derived by encrypting email and password with a static key, a weak token design with no existing Swift query.
  • An app delegate that does not obscure the window on backgrounding is a missing-API check, expressible as an audit style query.
  • Keychain queries without a restrictive kSecAttrAccessible value have no existing Swift query.
  • Sensitive responses cached by returnCacheDataElseLoad have no covering query.
  • Sensitive data lingering in a long-lived property without being cleared is a lifecycle pattern with no existing Swift query.

Linked findings (gap-key: swift/query-create/credential-and-data-exposure)

Repo CWE Severity AI scan alert Summary
Swift.nV CWE-200 medium https://github.com/codeql-forks-felickz/Swift.nV/security/code-scanning/38 The copy action writes the plaintext decrypted value to UIPasteboard.general and does not set an expiration date, clear it, or use a local-only pasteboard. The secret can remain available to other applications/pasteboard readers and to the user after locking or leaving the secret manager, defeating the app's access control for copied credentials.
OversecuredVulnerableiOSApp CWE-522 medium https://github.com/codeql-forks-felickz/OversecuredVulnerableiOSApp/security/code-scanning/17 On successful authentication the app builds the session token by concatenating the email and password and encrypting them with a static key
iGoat-Swift CWE-200 medium https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/49 The app has screens that display password-reset answers and payment data, but AppDelegate does not obscure the window when the application r
iGoat-Swift CWE-922 low https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/39 KeychainPasswordItem.keychainQuery(withService:account:accessGroup:) builds every SecItemAdd/SecItemUpdate/SecItemCopyMatching query
iGoat-Swift CWE-922 medium https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/26 The request for key material explicitly uses .returnCacheDataElseLoad with the default URL session, allowing the HTTP response containing
iGoat-Swift CWE-316 medium https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/31 After payment, the full card number is copied into a long-lived view-controller property and neither that property nor the input field is cl
iGoat-Swift CWE-200 medium https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/56 The view collects password-reset security answers but does not obscure or clear its text fields when the application enters the background.

Findings come from AI Scan on public synthetic apps. Hypotheses above are unverified until reproduced with a test database. Verify first whether CodeQL already covers a case (for example via a different query or threat model) before adding code.

Handling decision

  • Type: Query Create
  • Decision: Create a new CodeQL query. No existing query covers these patterns (most findings are gap type query-absent or missing-query). Because coverage of lower-severity patterns can be heuristic, target Community Packs unless precision is shown to be high enough for github/codeql.
  • Recommended actions across the findings: write-new-query (7)

Patterns in this gap

  • background-snapshot-exposure (2 findings), for example iGoat-Swift iGoat-Swift/iGoat-Swift/AppDelegate.swift
  • missing-query (1 finding), for example Swift.nV Swift.nV/NVEditItemViewController.swift
  • credential-derived-session-token (1 finding), for example OversecuredVulnerableiOSApp OVIA/Network/NetworkCalls.swift
  • keychain-accessibility (1 finding), for example iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Exercises/InsecureLocalDataStorage/KeychainAnalyze/KeychainPasswordItem.swift
  • sensitive-response-caching (1 finding), for example iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Exercises/InsecureLocalDataStorage/WebKit Cache/WebkitCacheExerciseVC.swift
  • sensitive-data-retained-in-memory (1 finding), for example iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Exercises/Memory Management/MemoryManagementVC.swift

Finding details

Each finding below has its own context so the agent can work from this issue alone.

1. Swift.nV Swift.nV/NVEditItemViewController.swift:203 (CWE-200, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Swift.nV/security/code-scanning/38
  • AI Scan message: The copy action writes the plaintext decrypted value to UIPasteboard.general and does not set an expiration date, clear it, or use a local-only pasteboard. The secret can remain available to other applications/pasteboard readers and to the user after locking or leaving the secret manager, defeating the app's access control for copied credentials.
  • Why CodeQL appears to miss it: missing-query: No installed query covers sensitive values copied to the global pasteboard without expiration or local-only options.
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
2. OversecuredVulnerableiOSApp OVIA/Network/NetworkCalls.swift:21 (CWE-522, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/OversecuredVulnerableiOSApp/security/code-scanning/17
  • AI Scan message: On successful authentication the app builds the session token by concatenating the email and password and encrypting them with a static key
  • Context for the agent: A Swift network call builds a session token by concatenating email and password and encrypting with a hard-coded key. CodeQL would need a query linking password sources and a constant key to a stored or returned token.
  • Why CodeQL appears to miss it: query-absent: Session token is derived by encrypting email and password with a static key, a weak token design with no existing Swift query.
  • Recommended action from the comparison: write-new-query (classification confidence: low)
3. iGoat-Swift iGoat-Swift/iGoat-Swift/AppDelegate.swift:10 (CWE-200, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/49
  • AI Scan message: The app has screens that display password-reset answers and payment data, but AppDelegate does not obscure the window when the application r
  • Context for the agent: A Swift AppDelegate does not implement applicationWillResignActive or similar to hide sensitive screens. CodeQL would need an absence query over app delegate lifecycle methods.
  • Why CodeQL appears to miss it: query-absent: An app delegate that does not obscure the window on backgrounding is a missing-API check, expressible as an audit style query.
  • Recommended action from the comparison: write-new-query (classification confidence: low)
4. iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Exercises/InsecureLocalDataStorage/KeychainAnalyze/KeychainPasswordItem.swift:163 (CWE-922, low)
  • AI Scan alert: https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/39
  • AI Scan message: KeychainPasswordItem.keychainQuery(withService:account:accessGroup:) builds every SecItemAdd/SecItemUpdate/SecItemCopyMatching query
  • Context for the agent: A Swift keychain helper builds query dictionaries for add, update and copy without setting an accessibility attribute. CodeQL would need a query on missing or weak kSecAttrAccessible in keychain item dictionaries.
  • Why CodeQL appears to miss it: query-absent: Keychain queries without a restrictive kSecAttrAccessible value have no existing Swift query.
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
5. iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Exercises/InsecureLocalDataStorage/WebKit Cache/WebkitCacheExerciseVC.swift:45 (CWE-922, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/26
  • AI Scan message: The request for key material explicitly uses .returnCacheDataElseLoad with the default URL session, allowing the HTTP response containing
  • Context for the agent: A Swift controller requests key material with returnCacheDataElseLoad on the default session. CodeQL would need an audit query for cache policies on requests carrying sensitive data.
  • Why CodeQL appears to miss it: query-absent: Sensitive responses cached by returnCacheDataElseLoad have no covering query.
  • Recommended action from the comparison: write-new-query (classification confidence: low)
6. iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Exercises/Memory Management/MemoryManagementVC.swift:18 (CWE-316, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/31
  • AI Scan message: After payment, the full card number is copied into a long-lived view-controller property and neither that property nor the input field is cl
  • Context for the agent: MemoryManagementVC.swift:18 copies a full card number from a text field into a view-controller property that is never cleared. CodeQL would need a query for sensitive values stored in long-lived properties with no reset path; precision is likely audit level.
  • Why CodeQL appears to miss it: query-absent: Sensitive data lingering in a long-lived property without being cleared is a lifecycle pattern with no existing Swift query.
  • Recommended action from the comparison: write-new-query (classification confidence: low)
7. iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Exercises/SideChannelDataLeaks/Backgrounding/BackgroundingExerciseVC.swift:3 (CWE-200, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/56
  • AI Scan message: The view collects password-reset security answers but does not obscure or clear its text fields when the application enters the background.
  • Context for the agent: BackgroundingExerciseVC.swift:3 collects security answers in text fields but never hides them in applicationDidEnterBackground. CodeQL would need a structural audit query for sensitive input views lacking a background-obscuring handler.
  • Why CodeQL appears to miss it: query-absent: Failing to obscure sensitive views on backgrounding is a UI lifecycle check with no existing Swift query.
  • Recommended action from the comparison: write-new-query (classification confidence: low)

Expected Severity

Medium

Code Examples

See the linked alerts above for the vulnerable pattern; reduce each to a minimal test case with a safe counterpart that should not alert.

CWE/CVE Reference (Optional)

CWE-200, CWE-316, CWE-522, CWE-922

References (Optional)

https://cwe.mitre.org/data/definitions/200.html

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    enhancement
    severity:medium
    on Oct 31, 2026
  2. Copilot commented on Oct 31, 2026

    Copilot

    The agent encountered an error and was unable to start working on this issue: Please try again later, or contact support if the problem persists. (Request id: F340:12A606:456BCC0:E3DEC41:6AE56313)

  3. assigned and unassigned on Oct 31, 2026
  4. added
    precision:low
    tags:experimental
    on Nov 3, 2026
  5. felickz commented on Nov 3, 2026

    @felickz
    Author

    Upstream triage

    precision:low Audit-grade or weak signal. Community Packs, always tags:experimental. tags:experimental Goes to Community Packs: performance, false-positive or synthetic-only concerns.

    Community Packs, experimental. Recommended for the Community Packs repository, not github/codeql. The issue is labeled tags:experimental for this.

    Linked pull request: #352

    Why. Six unrelated checks share one low-precision audit query. Most depend on identifier names (sensitive, decrypt, token, security answer) and on whole-file or whole-program absence checks (no kSecAttrAccessible, property never cleared, no backgrounding hook) that real apps satisfy elsewhere. The stock Swift suite has no overlap, but nothing here is precise enough for github/codeql. Fit for separate experimental Community Packs audit queries.

    Change New query
    Target New 6-in-1 query: UIPasteboard, keychain accessibility, URL cache policy, backgrounding snapshot, retained properties
    Precision assessed low (declared low in the pull request). Six unrelated checks in one query. Most rely on identifier-name regexps (SensitiveExpr, decrypt/plaintext, token/session, security answer) or whole-file and whole-program absence checks (no kSecAttrAccessible, never cleared, no backgrounding hook).
    Real-world basis partial. UIPasteboard, Keychain Services, URLRequest cache policy and UIApplicationDelegate are public Apple APIs, but triggers such as security answer fields and decrypted names are fitted to the training apps.
    Stock overlap none. Checked local stock swift-queries 1.3.10 and swift-all 6.8.3: nothing models UIPasteboard, keychain accessibility, cache policy or backgrounding; cleartext-storage queries use other sinks.
    Concerns, overlap and next steps

    False-positive concerns

    • Intentional copy of a password or secret by the user (reveal and copy UI) is reported as exposure; no untrusted data is involved
    • SecItemAdd alerts whenever the file never mentions kSecAttrAccessible, though Apple's default is WhenUnlocked and non-secret items are common
    • Backgrounding check misses protection inherited from an app delegate base class or added by a third-party library, so protected apps still alert
    • Cache policy alert fires in any function that mentions token, key, password or auth strings, whether or not the response is sensitive
    • Property alert fires for any assignment to a class property named like password or card number unless an empty value is assigned somewhere

    Performance concerns

    • isCallArgumentExpr joins expressions with call arguments by file and line range; cost on large databases is unmeasured

    Heuristics used

    • regexps on identifier names: decrypt|plaintext|cleartext, token|session|cookie, security/secret answer
    • SensitiveExpr and HeuristicNames name matching as the flow source
    • absence checks: no kSecAttrAccessible in file, no clearing assignment, no backgrounding method
    • substring match on encrypt in function names; regexp over string literals for token|key|password

    What an upstream change would look like. Split into single-purpose audit queries under swift/src/<category>/ in Community Packs (the Swift pack has no queries yet, so wire them into suites/swift.qls) with tests in swift/test/. No github/codeql change.

    Before opening an upstream pull request

    • Split the six patterns into separate queries, each with its own id, precision and tests
    • Add a true positive from a real, non-training Swift project for each query kept
    • Replace decrypt/plaintext name regexps with SensitiveExpr or explicit APIs and drop security-answer naming
    • Rework the SecItemAdd check: default accessibility is WhenUnlocked, so flag only explicit weak classes such as kSecAttrAccessibleAlways
    • Check run time of the isCallArgumentExpr join on a large Swift database

    Split note. Closest to reusable: the kSecAttrAccessibleAlways reference check and the pasteboard flow check. The default-keychain, backgrounding, cache-policy and retained-property checks are heuristic audit logic and should stay experimental or be dropped.

    This is a recommendation only. A human reviews it before any pull request is opened against github/codeql or the Community Packs repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CWE-200CWE-316CWE-522CWE-922enhancementprecision:lowquery-createseverity:mediumtags:experimental

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions