Skip to content

Replay: Remove images that are on localhost or private IP #7184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lucas-zimerman opened this issue Feb 14, 2023 · 8 comments
Closed

Replay: Remove images that are on localhost or private IP #7184

lucas-zimerman opened this issue Feb 14, 2023 · 8 comments
Labels
Package: replay Issues related to the Sentry Replay SDK Type: Improvement

Comments

@lucas-zimerman
Copy link
Contributor

lucas-zimerman commented Feb 14, 2023

Problem Statement

If a given recording captures images containing an URL to localhost or a Private IP, you'll get a CSP or connection refused error on Console Sample: https://sentry-sdks.sentry.io/replays/sentry-capacitor:5e61855fc88345e788a5317684ba22ee/?referrer=%2Fdiscover%2F%3AeventSlug%2F&t=56&t_main=console

image

Solution Brainstorm

Replace the URL containing images from localhost/private IP with a default image or delete it. This is an useful feature for webapps where most of the images are stored locally.

Related to getsentry/sentry-capacitor#318

@brnbs
Copy link

brnbs commented Feb 16, 2023

It would also be helpful for electron apps if we could implement our own URL override logic. For example, if I host the assets packaged into the electron app on a public server and change the URL during recording, I could load the images (and CSS files?) in Session Replay.

@mydea
Copy link
Member

mydea commented Feb 16, 2023

Hey there!

Right now, I think the best solution for this is to ensure any images (or at least any images that are hosted on localhost/private IPs) are blocked. If you opted out of blockAllMedia, you can do that via block: ['img'] or a more specific selector of your choosing.

Mid-term, we are investigating asset caching, which may help in some way with this problem - see: #7007

To make sure, could you paste your replay config here?

@lucas-zimerman
Copy link
Contributor Author

lucas-zimerman commented Feb 16, 2023

Hey there!

Right now, I think the best solution for this is to ensure any images (or at least any images that are hosted on localhost/private IPs) are blocked. If you opted out of blockAllMedia, you can do that via block: ['img'] or a more specific selector of your choosing.

Mid-term, we are investigating asset caching, which may help in some way with this problem - see: #7007

To make sure, could you paste your replay config here?

blockAllMedia does work indeed with images, but it doesn't seems to remove the following code/image from the html

  <link rel="icon" type="image/png" href="assets/icon/favicon.png"/>

Is there another way to remove this link or reference?

EDIT: Sample here: https://github.com/lucas-zimerman/sample-react

But using the following options:

stickySession: true, 
sessionSampleRate: 1.0, 
blockAllMedia: false

@mydea
Copy link
Member

mydea commented Feb 16, 2023

I think it should work to block this with a selector like this:

new Replay({
  block: ['link[rel="icon"]']
})

You can add any further CSS selectors in there to block them from being rendered!

We may want to add this to the blockAllMedia setting as well cc @billyvg ?

@lucas-zimerman
Copy link
Contributor Author

I think it should work to block this with a selector like this:

new Replay({
  block: ['link[rel="icon"]']
})

You can add any further CSS selectors in there to block them from being rendered!

We may want to add this to the blockAllMedia setting as well cc @billyvg ?

Oh that did the trick, and also this was also helpful for me to sort the CSP errors that I saw on #7183 by adding this block rule: 'base[href="/"]'

@mydea
Copy link
Member

mydea commented Feb 16, 2023

nice! Thanks for writing in.

@mydea mydea closed this as completed Feb 16, 2023
@AbhiPrasad AbhiPrasad added Package: replay Issues related to the Sentry Replay SDK and removed Status: Untriaged labels Feb 16, 2023
@lucas-zimerman
Copy link
Contributor Author

nice! Thanks for writing in.

Is it ok if I open a PR adding both base[href="/"]' and link[rel="icon"] to the block list?

@billyvg
Copy link
Member

billyvg commented Feb 16, 2023

@lucas-zimerman That'd be great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: replay Issues related to the Sentry Replay SDK Type: Improvement
Projects
None yet
Development

No branches or pull requests

5 participants