question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot bind SafeUrl to SVGImageElement

See original GitHub issue

🐞 bug report

Affected Package

The issue is likely caused by package @angular/core

Is this a regression?

No. If it is a regression, I'm not aware of it.

Description

I have a template that is a more complex version of this:

<svg xmlns="http://www.w3.org/2000/svg" id="svg">
    <image [attr.href]="aSafeUrl"></image>
</svg>

At runtime, no image is shown, no error is in the JavaScript console, and the DOM look like this (simplified):

<svg xmlns="http://www.w3.org/2000/svg" id="svg">
    <image href="SafeValue must use [property]=binding: app://localhost/path/image.png (see http://g.co/ng/security#xss)"></image>
</svg>

Is suspect that the proper binding for SafeUrls to SVGImageElement.href is missing.

When I use an [href] binding instead of [attr.href] Angular tells me that I’m trying to bind to a readonly property.

Context

This is part of an Apache Cordova project targeting the latest iOS version. iOS/cordova-ios@6 considers the file: protocol to be unsafe, so we use the synthetic app://localhost protocol and host. That’s probably why Angular deems the URLs to be unsafe. We wrap them using DomSanitizer.bypassSecurityTrustUrl(), but it seems that we can only use SafeUrls with specific bindings, which don’t exist for SVGImageElements. We use SVGs to support taking notes on images.

πŸ”¬ Minimal Reproduction

πŸ”₯ Exception or Error

SafeValue must use [property]=binding: app://localhost/path/image.png (see http://g.co/ng/security#xss)

🌍 Your Environment

Angular Version:

Angular CLI: 9.1.7
Node: 12.16.3
OS: darwin x64

Angular: 9.1.11
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.7
@angular-devkit/build-angular     0.901.8
@angular-devkit/build-optimizer   0.901.8
@angular-devkit/build-webpack     0.901.8
@angular-devkit/core              9.1.7
@angular-devkit/schematics        9.1.7
@angular/cli                      9.1.7
@angular/http                     4.4.7
@ngtools/webpack                  9.1.8
@schematics/angular               9.1.7
@schematics/update                0.901.7
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.43.0

Anything else relevant?

We don’t use the Angular CLI for building.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
crisbetocommented, Sep 28, 2020

It might be worth trying to bind to xlink:href instead.

0reactions
Chiffcommented, Aug 17, 2021

I’ve found a β€œworkaround”. You can simply put unsanitized URL into [attr.href] or [attr.xlink:href] on SvgImage element. I have tested this with the Base64 image.

//ts
imgSrc = apiCall().response; // data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAEYAAABkCAYAA..

//html
<image [attr.href]="imgSrc" ... ></image>

// result
<image x="0" y="0" href="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAEYAAABkCAYAA..." width="2480" height="3507"></image>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I display a SafeUrl or a SafeResourceUrl?
The error says use [property] binding - it means [innerHTML] for html. You want to display this value as html (not url or...
Read more >
goog.ui.PopupMenu - Google
A basic menu class. new PopupMenu( opt_domHelper , opt_renderer ). Parameters. opt_domHelper, (goog.dom.
Read more >
Untitled
Bxm9 ride schedule, Ptx can't sleep love live, Pristine chapel lakeside, Eva deroo, ... Alliance trucking as, Monad bind function, Farfel's friends rescue?...
Read more >
Untitled
... Trospium 20 mg tab, Creel of eels, I can't feel my face lyrics official, ... star taxis windsor, Safelink replacement phone status,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found