Skip to content

Filter untrusted annotation links in the native PDF viewer - #102754

Merged
marcaaron merged 1 commit into
mainfrom
mjasikowski/filter-native-pdf-links
Oct 1, 2026
Merged

marcaaron merged 1 commit into
mainfrom
mjasikowski/filter-native-pdf-links

Conversation

@mjasikowski

@mjasikowski mjasikowski commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Filter untrusted PDF annotation links before the native viewer forwards them to the operating system or the travel flow.

  • Allow only absolute external HTTP(S) URLs.
  • Reject custom schemes, malformed/relative URLs, and HTTP(S) links to app hosts derived from the existing linking prefixes.
  • Normalize host casing and trailing dots so equivalent app-host URLs remain blocked.
  • Preserve external web links and the existing authenticated external travel-link flow.
  • Apply the filter to all uses of the native PDF viewer, including attachments. Web PDF rendering and general deep-link/authentication handling are unchanged.

This is scoped PDF-viewer containment, not a general deep-link fix. It does not inspect external websites' redirect destinations. Non-HTTP(S) annotations, including mail and phone links, are also blocked.

Fixed Issues

For https://github.com/Expensify/Expensify/issues/687024
PROPOSAL: N/A — internal mitigation.

Tests

For manual replication, follow the concrete PDF download/send/open/tap steps in QA Steps below. Native-device verification is pending; automated results are recorded in AI Tests.

AI Tests

Performed on an isolated branch based on current main, reusing the existing checkout's installed dependencies:

  • Passed: npm test -- --runInBand --silent --runTestsByPath tests/unit/IsAllowedPDFLinkTest.ts tests/unit/NativePDFViewTest.tsx tests/unit/libs/TravelUtilsTest.ts — 3 suites, 65 tests. Existing duplicate-manual-mock warnings remain.
  • Passed: npm run lint-changed and targeted npm run lint -- src/components/PDFView/index.native.tsx src/components/PDFView/isAllowedPDFLink.ts tests/unit/IsAllowedPDFLinkTest.ts tests/unit/NativePDFViewTest.tsx.
  • Passed: node_modules/.bin/oxfmt --check src/components/PDFView/index.native.tsx src/components/PDFView/isAllowedPDFLink.ts tests/unit/IsAllowedPDFLinkTest.ts tests/unit/NativePDFViewTest.tsx.
  • Passed: npm run react-compiler-compliance-check -- check-changed.
  • Passed: npm run spell-changed and git diff --check.
  • Blocked: npm run typecheck reports errors in untouched files involving missing MFA action constants (CHANGE_PRIMARY_LOGIN, ADD_DELEGATE, UPDATE_DELEGATE), emoji/parser APIs, and Onyx exportState. No errors were reported in the changed files. Some failures reflect the reused dependencies not matching current main.
  • Incomplete: full-repository npm run lint exceeded the 120-second timeout.
  • Not run: full Jest suite, Storybook smoke test, native-device QA, offline-device QA, or high-traffic-account testing.

Offline tests

Pending device verification:

  1. Open both PDFs from the QA steps while online so they are cached. Enable airplane mode and turn Wi-Fi off.
  2. Reopen each cached attachment and tap a blank area of the PDF page. Expected: neither PDF signs you out or navigates away from the viewer.
  3. Restore connectivity before sending the confirmation message in QA step 6.

QA Steps

Run on iOS and Android native, using only test accounts you own. Device verification is still pending.

  1. Install a native build containing this PR and sign in to your recipient test account.
  2. On a computer, save these two PDFs from the original report (right-click each link and choose Save Link As):
  3. In NewDot's desktop/web app, sign in to a second test account you own. Open a chat with the recipient account, drag each downloaded PDF into the message composer, and send it. Use the same environment as the native build.
  4. On the recipient's native app, open that chat and tap transition_control.pdf to open it in the in-app PDF attachment viewer. Tap a blank area in the center of the page three times. The link annotation covers the entire page, so there is no visible link to find.
  5. Close the viewer, open signout_poc.pdf in the same way, and tap a blank area of its page three times.
  6. Close the viewer and send a normal text message in the chat to confirm the same account is still signed in and usable.

Expected with this PR: neither PDF logs the recipient out, opens a login/session-expired screen, opens a browser, or navigates to another app screen. The PDF stays open during the taps; normal viewer-control toggling is fine.

To reproduce the original bug: perform steps 2–5 on an affected build without the fix, using your own accounts. Tapping the PDF page is expected to sign the recipient out. Repeat on the PR build to verify that the same PDF no longer does so. Do not open the PDFs in Files, Preview, or an external PDF app; this flow tests NewDot's viewer.

PR Author Checklist

  • Verify that no new errors appear in the JS/native logs
  • 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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

Pending native-device QA; no recording captured.

Android: mWeb Chrome

N/A — native PDF viewer only; web rendering is unchanged.

iOS: Native

Pending native-device QA; no recording captured.

iOS: mWeb Safari

N/A — native PDF viewer only; web rendering is unchanged.

MacOS: Chrome / Safari

N/A — native PDF viewer only; web rendering is unchanged.

@mjasikowski
mjasikowski marked this pull request as ready for review October 1, 2026 12:57
@mjasikowski
mjasikowski requested review from a team as code owners October 1, 2026 12:57
@melvin-bot
melvin-bot Bot requested review from garrettmknight and marcaaron and removed request for a team October 1, 2026 12:57
@melvin-bot

melvin-bot Bot commented Oct 1, 2026

Copy link
Copy Markdown

@marcaaron 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]

@garrettmknight
garrettmknight removed their request for review October 1, 2026 16:29

Copy link
Copy Markdown
Contributor

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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

@marcaaron
marcaaron merged commit a6a7b60 into main Oct 1, 2026
47 of 54 checks passed
@marcaaron
marcaaron deleted the mjasikowski/filter-native-pdf-links branch October 1, 2026 22:57
@OSBotify

OSBotify commented Oct 1, 2026

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.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify OSBotify mentioned this pull request Oct 4, 2026
59 tasks done
@OSBotify

OSBotify commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/marcaaron in version: 9.5.2-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed. This PR is a security fix that blocks unsafe links inside PDFs opened in the mobile app's viewer, and no help article describes tapping links inside PDF attachments, so no sentence became incorrect.


view run

@OSBotify

OSBotify commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Julesssss in version: 9.5.2-4 🚀

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

Bundle Size Analysis (Sentry):

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.

4 participants