Skip to content

fix(auth): disable URL caching in FoundationClientEngine to prevent credentials being persisted to Cache.db - #4238

Merged
harsh62 merged 1 commit into
mainfrom
fix/foundation-client-disable-url-cache
Jun 26, 2026
Merged

fix(auth): disable URL caching in FoundationClientEngine to prevent credentials being persisted to Cache.db#4238
harsh62 merged 1 commit into
mainfrom
fix/foundation-client-disable-url-cache

Conversation

@harsh62

@harsh62 harsh62 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Issue #

Description

A test found that user credentials and Cognito tokens were being persisted to Cache.db in the app container of iOS applications using this library.

The root cause is in FoundationClientEngine, the base HTTP client used by the AWS SDK Swift service clients (Cognito Identity / Identity Provider, etc.) through PluginClientEngine.baseClientEngine(for:). It used URLSession.shared, whose default configuration includes an on-disk URLCache. As a result, responses carrying tokens and AWS credentials were written to Cache.db, where they could be recovered by inspecting the device.

This fix uses a dedicated URLSession configured with urlCache = nil and a reloadIgnoringLocalCacheData request cache policy, so these responses are never persisted to disk. This mirrors the cache-disabling behavior already applied to the Hosted UI URLSession in AWSCognitoAuthPlugin+Configure.swift (makeURLSession()).

The fix is applied at the library level and requires no app-side changes.

Note for adopters: this stops future caching. Tokens already written to Cache.db on existing installs remain until that cache is cleared; apps may wish to call URLCache.shared.removeAllCachedResponses() once on upgrade to purge anything already persisted.

General Checklist

  • Added new tests to cover change, if needed
  • Build succeeds with all target using Swift Package Manager
  • All unit tests pass
  • All integration tests pass
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)
  • Documentation update for the change if required
  • PR title conforms to conventional commit style
  • New or updated tests include Given When Then inline code documentation and are named accordingly testThing_condition_expectation()
  • If breaking change, documentation/changelog update with migration instructions

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The FoundationClientEngine is the base HTTP client used by the AWS SDK
service clients (Cognito Identity / Identity Provider, etc.) for credential
and token exchange. It previously used URLSession.shared, whose default
configuration includes an on-disk URLCache. As a result, responses carrying
Cognito tokens and AWS credentials were persisted to the app container's
Cache.db, where they could be recovered by inspecting the device.

Use a dedicated URLSession with urlCache = nil and a
reloadIgnoringLocalCacheData policy so these responses are never written to
disk. This mirrors the cache-disabling behavior already applied to the
Hosted UI URLSession in AWSCognitoAuthPlugin+Configure.
@harsh62
harsh62 requested a review from a team as a code owner June 26, 2026 14:17
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@harsh62
harsh62 temporarily deployed to IntegrationTest June 26, 2026 14:17 — with GitHub Actions Inactive
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.84%. Comparing base (9db19e5) to head (1a15b84).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4238      +/-   ##
==========================================
- Coverage   66.85%   66.84%   -0.02%     
==========================================
  Files        1151     1151              
  Lines       43869    43869              
==========================================
- Hits        29329    29323       -6     
- Misses      14540    14546       +6     
Flag Coverage Δ
API_plugin_unit_test 68.33% <ø> (ø)
AWSPluginsCore 68.07% <ø> (ø)
Amplify 47.49% <ø> (-0.03%) ⬇️
Amplify_Foundation_Bridge_unit_test 62.28% <ø> (ø)
Amplify_Foundation_unit_test 67.64% <ø> (ø)
Analytics_plugin_unit_test 83.43% <ø> (ø)
Auth_plugin_unit_test 72.49% <ø> (-0.14%) ⬇️
DataStore_plugin_unit_test 82.08% <ø> (+0.19%) ⬆️
Firehose_plugin_unit_test 53.15% <ø> (ø)
Geo_plugin_unit_test 73.39% <ø> (ø)
Kinesis_plugin_unit_test 52.17% <ø> (ø)
Logging_plugin_unit_test 64.86% <ø> (ø)
Predictions_plugin_unit_test 33.89% <ø> (ø)
PushNotifications_plugin_unit_test 85.66% <ø> (ø)
RecordCache_unit_test 76.40% <ø> (ø)
Storage_plugin_unit_test 78.67% <ø> (ø)
unit_tests 66.84% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@harsh62
harsh62 merged commit 56b2c36 into main Jun 26, 2026
214 of 216 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants