Skip to content

Commit b817d16

Browse files
authored
Merge pull request #223 from briantrice/fix/security-csp-style-src
Fix/security csp style src
2 parents 3f3417e + c1cda9c commit b817d16

File tree

8 files changed

+96
-76
lines changed

8 files changed

+96
-76
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ devJS:
3030

3131
devCSS:
3232
@$(NODE_BIN)/node-sass $(EXAMPLE_SRC)/index.scss $(EXAMPLE_DIST)/index.css
33+
@$(NODE_BIN)/node-sass $(SRC)/index.scss $(EXAMPLE_DIST)/style.css
3334
@$(NODE_BIN)/node-sass -w $(EXAMPLE_SRC)/index.scss $(EXAMPLE_DIST)/index.css
3435

3536
devServer:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class | data-class | String | | extra custom class, can use !important to
6060
html | data-html | Bool | true, false | `<p data-tip="<p>HTML tooltip</p>" data-html={true}></p>` or `<ReactTooltip html={true} />`
6161
delayHide | data-delay-hide | Number | | `<p data-tip="tooltip" data-delay-hide='1000'></p>` or `<ReactTooltip delayHide={1000} />`
6262
delayShow | data-delay-show | Number | | `<p data-tip="tooltip" data-delay-show='1000'></p>` or `<ReactTooltip delayShow={1000} />`
63+
insecure | null | Bool | true, false | Whether to inject the style header into the page dynamically (violates CSP style-src but is a convenient default)
6364
border | data-border | Bool | true, false | Add one pixel white border
6465
getContent | null | Func or Array | () => {}, [() => {}, Interval] | Generate the tip content dynamically
6566
afterShow | null | Func | () => {} | Function that will be called after tooltip show

bin/transferSass.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@ function transferSass () {
1111
console.log(err)
1212
return
1313
}
14-
fs.writeFile(path.resolve(__dirname, '../src/style.js'), "export default '" + result.css.toString().replace(/\n/g, '') + "'", function (err) {
14+
var cssSource = result.css.toString()
15+
fs.writeFile(path.resolve(__dirname, '../src/style.js'), "export default '" + cssSource.replace(/\n/g, '') + "'", function (err) {
1516
if (err) {
1617
console.error(err)
1718
}
18-
console.log('css file has been transformed successful')
19-
process.exit()
19+
console.log('css file has been transformed to JS successful')
20+
fs.writeFile(path.resolve(__dirname, '../src/style.css'), cssSource, function (err) {
21+
if (err) {
22+
console.error(err)
23+
}
24+
console.log('css file has been transformed successful')
25+
process.exit()
26+
})
2027
})
2128
})
2229
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"dist/",
1515
"standalone/",
1616
"src/style.js",
17+
"src/style.css",
1718
"example/"
1819
]
1920
},

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ReactTooltip extends Component {
2929
offset: PropTypes.object,
3030
multiline: PropTypes.bool,
3131
border: PropTypes.bool,
32+
insecure: PropTypes.bool,
3233
class: PropTypes.string,
3334
id: PropTypes.string,
3435
html: PropTypes.bool,
@@ -48,6 +49,7 @@ class ReactTooltip extends Component {
4849
};
4950

5051
static defaultProps = {
52+
insecure: true,
5153
resizeHide: true
5254
};
5355

@@ -100,9 +102,12 @@ class ReactTooltip extends Component {
100102
}
101103

102104
componentDidMount () {
103-
this.setStyleHeader() // Set the style to the <link>
105+
const { insecure, resizeHide } = this.props
106+
if (insecure) {
107+
this.setStyleHeader() // Set the style to the <link>
108+
}
104109
this.bindListener() // Bind listener for tooltip
105-
this.bindWindowEvents(this.props.resizeHide) // Bind global event for static method
110+
this.bindWindowEvents(resizeHide) // Bind global event for static method
106111
}
107112

108113
componentWillReceiveProps (props) {

src/style.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)