I’d like to embed a jsfiddle in a conversation. How can we do that?
The iframe embed code looks like:
<iframe width="100%" height="300" src="//jsfiddle.net/trusktr/32cnvse3/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
In a discussion titled “Can we make custom oneboxes?” under the Support category, users explore embedding interactive code environments like jsfiddle and CodePen into Discourse posts. trusktr requests jsfiddle embedding support, sharing an iframe example. Falco notes CodePen is already whitelisted and suggests testing jsfiddle. sam emphasizes security: no JavaScript must execute before user consent to avoid “JavaScript bombs” — malicious or poorly written scripts that can crash browsers, leak data, or phish users. Mittineague confirms SitePoint only links to jsfiddles, not embeds them, citing safety. trusktr asks for clarification on “JavaScript bombs”; sam explains the wide-ranging risks. Mittineague demonstrates a simple loop alert bomb. trusktr questions why CodePen is embeddable while jsfiddle isn’t, given both use iframes. Falco links to a meta discussion. trusktr tests embedding a CodePen “JS Bomb” via iframe and HTML, both failing. Falco clarifies oneboxes require pasting a link alone on a line — and run only after clicking. trusktr observes no infinite loop executes, Falco attributes this to Chrome’s iframe sandbox. trusktr finds “Edit on CodePen” bypasses loop detection — but Falco notes this happens off-Discourse. trusktr tests further bombs (console.log, document.write) to probe browser resilience, noting potential crashes on less robust browsers. The core concern remains: safe, user-triggered execution only.
I’d like to embed a jsfiddle in a conversation. How can we do that?
The iframe embed code looks like:
<iframe width="100%" height="300" src="//jsfiddle.net/trusktr/32cnvse3/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
Codepen is whitelisted by default:
Maybe we can test jsfiddle, let me check.
The big thing that needs testing is that there is 0 JS execution prior to a user clicking “run”. We can not risk people setting up JavaScript bombs.
Yes, at SitePoint we onebox codepens, but fiddles are only linked to.
It works well, and so far, AFAIK hasn’t introduced risk.
https://www.sitepoint.com/community/t/css-hover-transition/238497/3?u=mittineague
What are those? Something that makes the CPU work 100%?
Well unrestricted JS can lead to an enormous class of issues, leaking confidential info via JSONP, high CPU when you hit a topic, trick users into thinking the page has information on it that is fake, phishing, the sky is the limit.
For a simple harmless example that is more representative of a common JavaScript newbie mistake than a malicious script, try running this and see how well you like it
for (var i = 0; i < 1000; i++) {
alert(i);
}
My bet is you close your browser or stop scripts well before it completes.
What exactly is different about codepen compared to jsfiddle that makes only codepen embeddable? Can’t both run javascript, and don’t both run in a iframe?
Testing codepen bomb attempt:
Well, apparently codepen iframe embed doesn’t work.
How about HTML:
See the Pen JS Bomb Example by Joseph Orbegoso Pea (@trusktr) on CodePen.
Nope. How about URL:
Like all oneboxes, you are supposed to paste a link on a line by itself.
And as you can see it doesn’t run until clicked.
Interesting, and I don’t see the result (infinite while loop that alerts).
It’s blocked by the sandbox for iframes since Chrome 46.
If we click “Edit on codepen” then it runs the code for the first time without the infinite loop detection!
codepen console.log bomb:
But then you are on the codepen website right? What does this has to do with Discourse?
Nothing unless the whole browser crashes. x} Probably Chrome won’t crash, but maybe some other browser?
Testing document.write bomb: