Skip to content

Commit 3c9dfa5

Browse files
authored
fix: csp headers violation @gracenoah graphql/codemirror-graphql#246 (#1044)
This PR fixes a Content Security Policy (CSP) violation for those who are using CSP headers and do not have script-src of unsafe-eval enabled. The way the code is written now, onHover is undefined in this call to setTimeout. Passing undefined to setTimeout triggers a CSP violation for 'unsafe-eval' because setTimeout thinks you are passing a string, which is not allowed. The CSP Violation: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: ... This PR moves the usage of onHover to after the function is defined, so that setTimeout is not called with undefined and there are no CSP violations.
1 parent a040098 commit 3c9dfa5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/codemirror-graphql/src/utils/info-addon.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ function onMouseOver(cm, e) {
5050

5151
const box = target.getBoundingClientRect();
5252

53-
const hoverTime = getHoverTime(cm);
54-
state.hoverTimeout = setTimeout(onHover, hoverTime);
55-
5653
const onMouseMove = function() {
5754
clearTimeout(state.hoverTimeout);
5855
state.hoverTimeout = setTimeout(onHover, hoverTime);
@@ -72,6 +69,10 @@ function onMouseOver(cm, e) {
7269
onMouseHover(cm, box);
7370
};
7471

72+
73+
const hoverTime = getHoverTime(cm);
74+
state.hoverTimeout = setTimeout(onHover, hoverTime);
75+
7576
CodeMirror.on(document, 'mousemove', onMouseMove);
7677
CodeMirror.on(cm.getWrapperElement(), 'mouseout', onMouseOut);
7778
}

0 commit comments

Comments
 (0)