Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

[Improvement] setTransformOrigin breaks CSP rule style-src: 'unsafe-inline' #2292

Closed
SirAuron opened this issue Feb 22, 2018 · 1 comment
Closed
Labels

Comments

@SirAuron
Copy link

While setting up a project with CSP rules, the console keeps telling me that the browser
"Refused to apply inline style because it violates the following Content Security Policy directive [...] 'unsafe-inline' ".

After a little bit of investigation, I found out that the function "setTransformOrigin" in the textfield component:

/**
 * Sets the transform origin given a user's click location.
 * @param {!Event} evt
 */

}, {
key: 'setTransformOrigin',
value: function setTransformOrigin(evt) {
  var targetClientRect = evt.target.getBoundingClientRect();
  var evtCoords = { x: evt.clientX, y: evt.clientY };
  var normalizedX = evtCoords.x - targetClientRect.left;
  var attributeString = 'transform-origin: ' + normalizedX + 'px center';

  this.adapter_.setAttr('style', attributeString);
}

applies the transform-origin property by directly setting style attribute, thus breaking the CSP rule mentioned above.

I was wondering if it is possible to change that function and make it CSP compliant.

@SirAuron SirAuron changed the title setTransformOrigin breaks CSP rule style-src: 'unsafe-inline' [improvement] [Improvement] setTransformOrigin breaks CSP rule style-src: 'unsafe-inline' Feb 22, 2018
@moog16
Copy link
Contributor

moog16 commented Feb 26, 2018

@SirAuron thanks for bringing this to our attention. We'll need to do some more investigation, but at first glance at this link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#Sources we might be able to fix it by changing our setAttr('style', key) call --> .style[key].

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants