Skip to content

[Payment due @nyomanjyotisa] Update cert pinning logic - #100965

Merged
cristipaval merged 7 commits into
Expensify:mainfrom
software-mansion-labs:chore/update-cert-pins-3
Sep 22, 2026
Merged

cristipaval merged 7 commits into
Expensify:mainfrom
software-mansion-labs:chore/update-cert-pins-3

Conversation

@staszekscp

Copy link
Copy Markdown
Contributor

Explanation of Change

Switches NewDot's certificate pins from leaf + issuing intermediate to root CA only.

Leaf/intermediate pins have already broken twice in production — Cloudflare rotated the www/secure edge cert from Let's Encrypt to Google Trust Services (2026-07-07), and Amazon rotated CloudFront's intermediate from RSA 2048 M01 to M04 (2026-07). Leaves are re-keyed on every renewal and every CA issues from a rotating pool of intermediates, so roots are the only durable pin target. Pinning roots survives leaf rotation, intermediate rotation, and (since all three Cloudflare CAs are pinned) a CA switch, without an emergency release.

Pins are now:

  • Cloudflare-fronted *.expensify.com hosts → ISRG Root X1/X2 (Let's Encrypt), GTS Root R1–R4, SSL.com TLS ECC/RSA Root CA 2022.
  • d2k5nsl2zxldvw.cloudfront.net → Amazon Root CA 1–4 + Starfield Services Root CA G2 (the only stable pin targets per AWS docs).

Pinned hosts are unchanged: www, secure, new, integrations, travel (.expensify.com), their staging.* counterparts, and d2k5nsl2zxldvw.cloudfront.net.

Updated across all pin targets — config/certificatePinning/pins.json (canonical), CertificatePinning.kt (OkHttp), CertificatePinning.swift (TrustKit), the react-native-nitro-fetch Cronet patch, and network_security_config_enforce.xml.

Two supporting changes:

anchoredChain() in CertificatePinning.kt — a TLS server never sends its root, so the OkHttp and HttpsURLConnection monitors now rebuild the validated chain up to its trust anchor (X509TrustManagerExtensions.checkServerTrusted) before checking pins. Without it root pins could never match there and every request would report a false mismatch. Android , OkHttp enforce mode, TrustKit and Cronet include the anchor natively.
scripts/generateCertificatePins.sh — for the same reason, roots can't be read off a live handshake, so the script now downloads the Mozilla CA bundle and verifies each root against SHA-256 fingerprints committed in its ROOT_MANIFEST (the fingerprints, not the download, are the source of trust). Adds --verify (confirms each live chain anchors at a pinned root), --refresh and --android, plus ROOTS_BUNDLE= for offline/CI use. The root cache is gitignored.

Still monitor-only (enforcePinning = false everywhere): mismatches are reported to Sentry, connections are not blocked. The root pin-set for Android lives in network_security_config_enforce.xml, ready to copy over when we flip to enforce.

No JS or UI changes.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/633469
PROPOSAL:

MOBILE-EXPENSIFY: https://github.com/Expensify/Mobile-Expensify/pull/14106

Tests

Run a release build on Android and iOS (pinning is a no-op in debug). Throughout, check Sentry for certificate_pinning_* events — there should be none.

  1. Log in and open a report → app loads, API calls succeed, no certificate errors.
  2. Open the app fresh (triggers OpenApp) → initializes and syncs without errors.
  3. On a workspace with an accounting connection (e.g. QuickBooks), Settings → Workspace → Accounting → Sync now → completes without a certificate error.
  4. Open the Travel tab and start the booking flow → content loads without errors.
  5. Open a report with an image attachment or receipt, then download it → renders and downloads without errors (covers Cronet/fetch and react-native-blob-util/OkHttp).

Offline tests

QA Steps

  1. Log in and open a report → app loads, API calls succeed, no certificate errors.
  2. Open the app fresh (triggers OpenApp) → initializes and syncs without errors.
  3. On a workspace with an accounting connection (e.g. QuickBooks), Settings → Workspace → Accounting → Sync now → completes without a certificate error.
  4. Open the Travel tab and start the booking flow → content loads without errors.
  5. Open a report with an image attachment or receipt, then download it → renders and downloads without errors (covers Cronet/fetch and react-native-blob-util/OkHttp).

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2026-09-09.at.14.15.51.mov
Android: mWeb Chrome
iOS: Native
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-09-09.at.14.05.34.mov
iOS: mWeb Safari
MacOS: Chrome / Safari

@staszekscp
staszekscp marked this pull request as ready for review September 11, 2026 13:25
@staszekscp
staszekscp requested review from a team as code owners September 11, 2026 13:25
@melvin-bot
melvin-bot Bot requested review from garrettmknight and linhvovan29546 and removed request for a team and garrettmknight September 11, 2026 13:25
@melvin-bot

melvin-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

@linhvovan29546 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team September 11, 2026 13:26
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR is possibly changing native code and/or updating libraries, it may cause problems with HybridApp. Please check if any patch updates are required in the HybridApp repo and run an AdHoc build to verify that HybridApp will not break. Ask Contributor Plus for help if you are not sure how to handle this. ⚠️

@staszekscp

Copy link
Copy Markdown
Contributor Author

cc: @nyomanjyotisa since you've been reviewing #100518

@staszekscp staszekscp mentioned this pull request Sep 11, 2026
38 tasks done

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e819ea708a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 78 to 79
// Google Trust Services (GTS Root R2 is not pinned: Mozilla removed it from its root store in 2026)
"sha256/hxqRlPTu1bMS/0DITB1SSu0vd4u/8l8TjPgfaAp63Gc=", // GTS Root R1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep GTS Root R2 in the platform pin set

Removing this root based on Mozilla's bundle is unsafe for the mobile clients: pinning is evaluated against each device's selected system trust anchor, and those stores can continue to trust GTS Root R2 independently of Mozilla. If Cloudflare serves a GTS R2 chain to such a device, TLS will otherwise validate but the new root-only pins will not match, causing monitor failures now and blocking all affected Expensify requests once enforce mode is enabled. Retain R2 in the native/Cronet pin lists until it is no longer trusted by the supported platform stores.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, on it

+ "C5+lpZ7tcVwmwQIMcRtPbsQtWLABXhQzejna0wHFr8M=", // ISRG Root X1
+ "diGVwiVYbubAI3RW4hB9xU8e/CH2GnkuvVFZE8zmgzI=", // ISRG Root X2
+ "brzvtCELCIZUo4sD/qPX0ccRtPsd3DY6RfmxpOU9oB4=", // Let's Encrypt YE1 intermediate (live ECDSA)
+ // Google Trust Services - backup CA
+ "hxqRlPTu1bMS/0DITB1SSu0vd4u/8l8TjPgfaAp63Gc=", // GTS Root R1
+ "Vfd95BwDeSQo+NUYxVEEIlvkOlWY2SalKK1lPhzOx78=", // GTS Root R2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staszekscp Could you regenerate this patch? The added R2 entry leaves the hunk count at 212 instead of 213, so patch-package cannot parse it. This also causes the CI installation failure.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved ✅

Comment thread scripts/generateCertificatePins.sh Outdated
"ISRG_Root_X1|96:BC:EC:06:26:49:76:F3:74:60:77:9A:CF:28:C5:A7:CF:E8:A3:C0:AA:E1:1A:8F:FC:EE:05:C0:BD:DF:08:C6"
"ISRG_Root_X2|69:72:9B:8E:15:A8:6E:FC:17:7A:57:AF:B7:17:1D:FC:64:AD:D2:8C:2F:CA:8C:F1:50:7E:34:45:3C:CB:14:70"
"GTS_Root_R1|D9:47:43:2A:BD:E7:B7:FA:90:FC:2E:6B:59:10:1B:12:80:E0:E1:C7:E4:E4:0F:A3:C6:88:7F:FF:57:A7:F4:CF"
"GTS_Root_R2|8D:25:CD:97:22:9D:BF:70:35:6B:DA:4E:B3:CC:73:40:31:E2:4C:F0:0F:AF:CF:D3:2D:C7:6E:B5:84:1C:7E:A8"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staszekscp The clean-checkout failure returns with R2 restored. The downloaded Mozilla bundle lacks it, and all six new tests fail on Node 26.5.0. Could we retain the pin but provide a fingerprint-verified R2 source that also works with --refresh?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved ✅

Comment thread scripts/generateCertificatePins.sh Outdated
local untrusted="${tmpdir}/untrusted.pem"
cat "${tmpdir}"/cert_*.pem > "$untrusted"

if openssl verify -CAfile "$roots_bundle" -untrusted "$untrusted" "${tmpdir}/cert_1.pem" >/dev/null 2>&1; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staszekscp Could we restrict verification to the supplied roots? With an unpinned test CA in OpenSSL’s default trust directory, --verify reports “chain anchors at a pinned root.” Disabling the default trust sources correctly rejects the same chain.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved ✅

@staszekscp

Copy link
Copy Markdown
Contributor Author

The suggestions have been applied!

@nyomanjyotisa

nyomanjyotisa commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android-pr100965.mp4
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

@staszekscp

Copy link
Copy Markdown
Contributor Author

Hey @nyomanjyotisa! 👋🏻 How is the review going?

@nyomanjyotisa

Copy link
Copy Markdown
Member

@staszekscp I haven’t found any further blocking code issues. Could you help trigger Android and iOS ad-hoc builds so I can finish testing and complete the reviewer checklist?

@staszekscp

Copy link
Copy Markdown
Contributor Author

@mountiny @cristipaval Hey guys! Could you run an ad-hoc standalone build for testing purposes, please? 🙏🏻

@github-actions

Copy link
Copy Markdown
Contributor

🚧 cristipaval has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

@nyomanjyotisa nyomanjyotisa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Internal/QA coverage is still needed for the iOS release build (my device isn’t provisioned).

@melvin-bot melvin-bot Bot changed the title Update cert pinning logic [Payment due @nyomanjyotisa] Update cert pinning logic Sep 21, 2026
@melvin-bot

melvin-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown

🎯 @nyomanjyotisa, thanks for reviewing and testing this PR! 🎉

A payment issue will be created for your review once this PR is deployed to production.
E/E issue linked to the PR - https://www.github.com/Expensify/Expensify/issues/633469.

If payment is not needed (e.g., regression PR review fix etc), react with 👎 to this comment to prevent the payment issue from being created.

cristipaval
cristipaval previously approved these changes Sep 21, 2026
@cristipaval

Copy link
Copy Markdown
Contributor

@staszekscp could you please resolve the conflicts?

@staszekscp

Copy link
Copy Markdown
Contributor Author

Resolved!

@cristipaval
cristipaval merged commit a26a563 into Expensify:main Sep 22, 2026
43 of 44 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 cristipaval has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/cristipaval in version: 9.4.92-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@izarutskaya

Copy link
Copy Markdown

@staszekscp can you please clear the steps? Thank you

no certificate errors.

@staszekscp

Copy link
Copy Markdown
Contributor Author

Hey @izarutskaya! Maybe I should have been clearer here - what I mean by "no certificate errors" is just that the content loads as usual (the change is supposed to block network request from unauthorized sources, but if we use the app normally, there should be no change, and all content should load correctly as on other PRs)

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/lakchote in version: 9.4.92-8 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@melvin-bot

melvin-bot Bot commented Sep 24, 2026

Copy link
Copy Markdown

🤖 Payment issue created: #102151

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.

5 participants