-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bugfix] Use CSSOM for style manipulations
Currently we assign the style property directly when manipulating CSS. This is an XSS vector, and prevents security conscious users from using a CSP that prevents this type of manipulation. We can avoid it by assigning style properties directly on the `element.style` object, which filters the text safely (as per CSSOM). fixes #566
- Loading branch information
Showing
4 changed files
with
58 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Component from '@ember/component'; | ||
import { equal } from '@ember/object/computed'; | ||
import { observer } from '@ember/object'; | ||
import { scheduleOnce } from '@ember/runloop'; | ||
|
||
export default Component.extend({ | ||
// Provided by subclasses | ||
columnMeta: null, | ||
|
||
classNameBindings: ['isFirstColumn', 'isFixedLeft', 'isFixedRight'], | ||
|
||
isFirstColumn: equal('columnMeta.index', 0), | ||
isFixedLeft: equal('columnMeta.isFixed', 'left'), | ||
isFixedRight: equal('columnMeta.isFixed', 'right'), | ||
|
||
// eslint-disable-next-line | ||
scheduleUpdateStyles: observer( | ||
'columnMeta.{width,offsetLeft,offsetRight}', | ||
'isFixedLeft', | ||
'isFixedRight', | ||
|
||
function() { | ||
scheduleOnce('actions', this, 'updateStyles'); | ||
} | ||
), | ||
|
||
updateStyles() { | ||
if (typeof FastBoot === 'undefined' && this.element) { | ||
let width = `${this.get('columnMeta.width')}px`; | ||
|
||
this.element.style.width = width; | ||
this.element.style.minWidth = width; | ||
this.element.style.maxWidth = width; | ||
|
||
if (this.get('isFixedLeft')) { | ||
this.element.style.left = `${Math.round(this.get('columnMeta.offsetLeft'))}px`; | ||
} else if (this.get('isFixedRight')) { | ||
this.element.style.right = `${Math.round(this.get('columnMeta.offsetRight'))}px`; | ||
} | ||
} | ||
}, | ||
|
||
didInsertElement() { | ||
this._super(...arguments); | ||
this.updateStyles(); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters