javascript - Prevent inline JS execution -


i have situation loading external html wysiwyg editor on web page. external html trusted source, , includes ever between 2 specific <div> tags number of different pages.

my problem of pages contain inline javascript event handlers. when working in wysiwyg editor, events cause execution of js.

mostly doesn't other fill console errors saying ... not defined, , may is, , wouldn't problem. still, it's messy, , don't know if there isn't page somewhere might execute alert(...) extremely annoying. code trusted, detached intended context, produced undesirable results.

i want find way globally prevent execution, preferably without modifying inline script. attach =false; each handler, have check incoming elements, , regular expressions, degrade performance. also, have remove before submitting edited html server, seems major pain, , difficult flawlessly.

is there way prevent online code being executed within particular context?

depending on browser trying support, can checkout 'content security policy' headers. checkout http://caniuse.com/contentsecuritypolicy details on browser support.

if target browser in list, csp can looking for. disable event handlers default. block execution of code embedded within on page in addition blocking event handlers. need move js code, if present on html page separate js, specify filename in safe-list , load js there.

csp set http headers new specification can set using meta tags well. checkout https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#html-meta-element--experimental.

for webkit supported browsers(chrome/safari) restrict load external source. can add list of accepted sources list , explore works you.

for firefox, though there in specification, not think meta tag supported yet. https://developer.mozilla.org/en-us/docs/security/csp/introducing_content_security_policy.

so summarize, long can set headers web-server hosting web page (unless want chrome/safari support), , target browser supports csp, might give shot.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -