<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Looker Engineering - Medium]]></title>
        <description><![CDATA[Engineering @ Looker. Our unique intelligence environment makes it easy for data analysts to create and curate custom data experiences - so they can give everyone in the business the freedom to explore the data that matters to them, in the context that makes it truly meaningful - Medium]]></description>
        <link>https://medium.com/looker-engineering?source=rss----b74412cf1aff---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Looker Engineering - Medium</title>
            <link>https://medium.com/looker-engineering?source=rss----b74412cf1aff---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:01:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/looker-engineering" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Turning Looker Up to 11]]></title>
            <link>https://medium.com/looker-engineering/turning-looker-up-to-11-daa00de88d4c?source=rss----b74412cf1aff---4</link>
            <guid isPermaLink="false">https://medium.com/p/daa00de88d4c</guid>
            <category><![CDATA[jdk]]></category>
            <category><![CDATA[jruby]]></category>
            <category><![CDATA[jdk-11]]></category>
            <category><![CDATA[looker]]></category>
            <category><![CDATA[openjdk]]></category>
            <dc:creator><![CDATA[Looker Engineering]]></dc:creator>
            <pubDate>Wed, 18 Nov 2020 19:17:53 GMT</pubDate>
            <atom:updated>2020-11-18T19:17:53.450Z</atom:updated>
            <content:encoded><![CDATA[<h4>Our experience upgrading from JRuby 9.1.17.0/OpenJDK8 to JRuby 9.2.13.0/OpenJDK11</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ncKSxR1cN-HHVf--UoOxEA.png" /><figcaption>HTTP Response time pre/post the JRuby upgrade (DataDog)</figcaption></figure><p><strong>By John W. Phillips and Kalen Peterson</strong></p><h3>Introduction</h3><p>This article describes Looker’s experience upgrading JRuby and Java versions. It starts with a description of our software stack, then gives a general outline of the phases of the project and the challenges we hit at each point. The genesis of this upgrade project was building internal and customer pressure to support OpenJDK11, which requires JRuby 9.2.10+. Additionally, we suspected (rightly) that there were a lot of performance gains to be had both in the JRuby upgrade itself and in the JDK upgrade.</p><h3>The Looker environment</h3><p>Looker’s software stack is JRuby running in a <em>puma</em>/<em>rack</em> web server, using <em>sequel</em> for ORM, and lots of lower level code built in Java and Kotlin. We have a Jenkins CI/CD system which runs unit tests, builds Looker, and runs integration tests using Cucu and Docker. Diving into the JRuby side in more detail, we use <em>rbenv</em> to manage the JRuby versioning, <em>bundler</em> for Ruby package management, and <em>warbler</em> to build the Looker artifact, a jar file.</p><p>Looker’s software stack originally used JRuby 1.7, and in 2016 we moved to JRuby 9.1.17.0. After this upgrade project we are now running JRuby 9.2.13.0 with support for Oracle JDK8, OpenJDK8, and OpenJDK11.</p><h3>The Upgrade Methodology</h3><p>We predicted up-front that the change set required for the upgrade would be large, so one decision we made was to roll any backwards-compatible changes needed for the upgrade directly into the main code branch. Theoretically you might consider keeping everything in a branch, but practically many of the changes were code cleanup, package upgrades, and the like which arguably should go to the main branch anyway. Also, given that we believed the upgrade project would take a long time it seemed impractical to keep a large delta in a branch for the duration of the effort.</p><p>Another best practice when doing package upgrades is to land them into the main branch at the beginning of a release cycle. This gives some time to catch and sort out any issues before the changes are released and propagated out to customers.</p><p>Lastly, if you haven’t done so, add logging of the JRuby and Java version you’re using. When switching back and forth between versions it’s easy to lose track of what is running where.</p><h3>The Ruby 2.3 -&gt; 2.5 Upgrade</h3><p>The first set of issues in the JRuby version upgrade was that in upgrading from JRuby 9.1.x to JRuby 9.2.x we were upgrading from Ruby version 2.3 to Ruby 2.5. This meant mostly converting all uses of Bignum and Fixnum in our codebase to Integer, as well as a few other changes. Also, most of the Ruby gems upon which we depend have minimum release versions where this conversion has been done, so we started to pick those up. Most of this work was straightforward. Of course, having a well built regression test system reduces the risk with these upgrades.</p><p>Even so, we encountered a handful of issues where these gem upgrades didn’t go smoothly. When we upgraded our <em>mail</em> gem to v2.7.0 to pick up the Ruby 2.5 updates it introduced a change in MIME type handling which was missed by our tests and caused an outage on our internal production instance. After backing out the change and debugging the issue we’re now on v2.6.6.</p><p>In any package/version upgrade project there will be secondary packages and functional areas related to the fact that you have a web application, and primary areas which are intricately connected to your product’s core value. In our case the <em>sequel</em> gem and database code paths are that primary area. We had been running a customized fork of Sequel v4.9 from ~2014, and after some discussion decided to target Sequel v4.49 but not move to v5.x. Moving to v4.49 brought in all of the Ruby 2.5 fixes, and there was only 1 Java 11 fix in the v5.x branch which we then back ported to our v4.49 fork.</p><h3>JRuby</h3><p>As the package upgrade work was tailing off we began doing test runs with different JRuby 9.2.x versions to sort out any initial issues. Technically this was very easy, just make a branch, change the version in the <em>rbenv</em> .ruby-version file, and run it through Jenkins.</p><p>The first layer of issues with changing JRuby versions were in 2 broad classes: JRuby bugs that we depended on which were fixed, and new JRuby issues or security improvements which required changes in our code. One interesting example of the former is <a href="https://github.com/jruby/jruby/issues/4260">a bug in the Ruby squiggly heredoc</a> which got fixed somewhere in JRuby 9.2.x. The bug changed how indentation of multi-line strings works. We didn’t have many multiline strings in our production code, but we used them all over the place in our tests to inline YAML, and many of them became unparseable with different indentation. After some debug we found that MRI and JRuby 9.2.x agreed on squiggly heredoc indentation and JRuby 9.1.x was the outlier, so we concluded that it was a JRuby bug fix and rolled in changes to our tests which worked with both JRuby versions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*p_-kvvJ23PYmEdclxR11tg.png" /></figure><p>One case of a JRuby improvement which caused an issue is Mutex no longer being marshallable. The fact that we were marshaling into caches objects with Mutexes is arguably bad by design, and with JRuby 9.2.x it stopped working. Here we chose a shortcut and built a MarshallableMutex, which unlocks on serialization, rather than a deeper analysis and redesign of our data structures.</p><p>In total we had around 15 unique issues which we worked through running our unit test suite with the JRuby upgrade. After root cause analysis most could be fixed in the main branch in a way that worked with both JRuby versions.</p><h3>Integration Testing</h3><p>We began our JRuby 9.2.x testing with the latest release at that time, JRuby 9.2.11.1. Once we worked through most of the issues in our unit tests we began to bump up against known JRuby issues. With JRuby 9.2.11.1 we hit <a href="https://github.com/jruby/jruby/issues/6210">this issue</a>. Once we realized what was blocking us we tried moving back to JRuby 9.2.8.0. In retrospect we could have saved some time by reading the JRuby release notes and Changelog, because next we ended up hitting a <a href="https://github.com/jruby/jruby/issues/5912">known issue</a> with <em>puma</em>. Since the previous issue affected JRuby 9.2.10.0 onwards and the latter issue affected versions up to JRuby 9.2.8.0, by process of elimination we moved to JRuby 9.2.9.0. Success!</p><h3>A Big Win</h3><p>The JRuby 9.1.17.0 -&gt; 9.2.9.0 upgrade was a big win. NewRelic metrics on our internal production instance showed GC latency down slightly and GC frequency ~60% lower. NewRelic also showed web transaction time ~50% lower, and DataDog showed Http response time ~80% lower. NewRelic data is collected with a <em>rack</em> shim, so it’s possible that the Datadog number reflected additional improvement in the <em>puma</em> layer outside of the NewRelic measurement universe. However, the one bitter outcome at this point was that we ended up on JRuby 9.2.9.0, and the first JRuby version to support OpenJDK11 is JRuby 9.2.10.0.</p><p>The JRuby developers had indicated that JRuby 9.2.11.1 was going to be the last JRuby release before JRuby 9.3.x, so internally at Looker we started bouncing around ideas for how to proceed. Members of our team had contributed to several JRuby projects previously, and a few had contacted the core JRuby development team in the past. Mostly due to the lack of other options, we decided to try to make a case for another JRuby release with a fix for <a href="https://github.com/jruby/jruby/issues/6210">the blocking issue</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*j3tva18eBmVSKHkxBePt8Q.png" /><figcaption>GC Frequency pre/post the JRuby upgrade (NewRelic)</figcaption></figure><h3>The Last Mile</h3><p>When asking for a bug fix from a team maintaining open source software there are plenty of “don’ts”. <strong>Everyone is busy, so it’s important to frame what feedback you have as a technical argument rather than as a complaint.</strong></p><p>Looker has a heavily multi-threaded JRuby application, and we were blocked from JRuby 9.2.11.1 and thus from OpenJDK11 by a JRuby multithreading bug. Part of JRuby’s core value proposition over Ruby is that it runs in the JVM and thus is a version of Ruby suitable for applications such as ours. Putting this together into a technical argument, we quickly found common ground with the JRuby development team when we explained it to them on the #jruby IRC channel. They agreed to do a JRuby 9.2.12.0 release with a fix for our issue.</p><p>In parallel with this effort we began to rethink how we were upgrading to new JRuby releases at Looker. Our basic methodology had always been to try moving forward to newer JRuby releases and see what the issues were. Thinking about where we were and what we had seen up to this point, it occurred to us that we had it backwards — we should be testing pre-release versions of JRuby and giving feedback so that we could use the release when it came out.</p><p>As the JRuby development team was working on the 9.2.12.0 release we began to experiment with how to plug pre-release versions of JRuby into our stack and run them through our Jenkins CI flow. Even though the JRuby team does publish nightly builds it turned out to be a difficult problem, because between <em>rbenv</em>, <em>bundler</em>, and <em>warbler</em> we could find no automated way to pick one up and use it.</p><p>Our second bitter setback came when the JRuby team released JRuby 9.2.12.0, our “Looker version”, and we hit <a href="https://github.com/jruby/jruby/issues/6319">a second multithreading bug</a>. We returned to the JRuby development team with our results and they agreed to do JRuby 9.2.13.0 with a fix to our second issue.</p><p>However, by this point we had developed a flow where we could manually build our Looker <em>warbler</em> jar artifact and run it through our Jenkins Cucu-based integration test suite. Given our new technique to “flip the paradigm”, as JRuby 9.2.13.0 was being developed we could test in parallel. As the JRuby development team worked we did several iterations of building the JRuby 9.2.13.0 branch, building our Looker jar using the custom JRuby, and running the Cucu tests. At the end, success! We were able to move to JRuby 9.2.13.0.</p><h3>OpenJDK11</h3><p>We needed a few more code changes to support OpenJDK11, but they were straightforward. After changing how we instantiate Nashorn and fixing an issue with casting classloaders, Looker was running with OpenJDK11. When our internal production instance moved from JDK8 to OpenJDK11 we saw more performance improvements: cpu utilization down from ~25% to ~10%, http response time ~35% better, JVM heap usage down ~10%. During our interaction with the JRuby development team we learned that crediting these improvements entirely to OpenJDK11 is not quite fair, since JRuby itself has lots of JDK11-specific improvements which were enabled by the switch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*5SGnAPYkWctIfOGSN1syEQ.png" /><figcaption>HTTP response time pre/post the OpenJDK8 -&gt; OpenJDK11 upgrade (DataDog)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*DOQko334zcEKqhEBk5JEmg.png" /><figcaption>Host CPU utilization pre/post the OpenJDK8 -&gt; OpenJDK11 upgrade (DataDog)</figcaption></figure><h3>Next Steps</h3><p>After this Java/JRuby upgrade project at Looker we have plenty of new ideas for how to make it smoother next time. We may build a Jenkins flow to build JRuby from source and run our CI flow using it, making it easier for us to move forward to new JRuby versions upon release. This could also be run with Java OpenJDK14 to set us up for that upgrade when we decide to take it on.</p><h3>Conclusion</h3><p>Even though it took over 9 months from start to finish, the JRuby/Java upgrade was a much needed modernization of the Looker software stack. Hopefully the example here and the project phases and issues we encountered will illuminate the work of anyone doing a project like this in the future.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=daa00de88d4c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/looker-engineering/turning-looker-up-to-11-daa00de88d4c">Turning Looker Up to 11</a> was originally published in <a href="https://medium.com/looker-engineering">Looker Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Engineering a Hackathon with Looker]]></title>
            <link>https://medium.com/looker-engineering/looker-hack-london-4e902f761acd?source=rss----b74412cf1aff---4</link>
            <guid isPermaLink="false">https://medium.com/p/4e902f761acd</guid>
            <category><![CDATA[london]]></category>
            <category><![CDATA[looker]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[hackathons]]></category>
            <category><![CDATA[business-intelligence]]></category>
            <dc:creator><![CDATA[Scott Sirowy]]></dc:creator>
            <pubDate>Thu, 18 Jul 2019 07:51:01 GMT</pubDate>
            <atom:updated>2019-07-18T07:51:01.540Z</atom:updated>
            <content:encoded><![CDATA[<h4>A breakdown of Hack:London hosted by Looker!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*UjZvntEnTM19IjcDkoz7vg@2x.png" /></figure><h3>Hackathons Are Important</h3><p>At Looker, we recognize the importance of hackathons. Before hosting our first ever external hackathon in 2018, we’d have internal hackathons (we would call them hackdays) every couple of months to let our engineers dream big and build their dream project. A number of important features in Looker came out of the minimum viable products built during our Looker hackdays.</p><p>Hackathons are important for our broader community too. A developer attending a Looker hackathon can use the time and resources provided to quickly build and iterate on projects that extend Looker. Attendees get to interact directly with both Looker employees and other Looker users who are experts in various aspects of Looker’s platform. Looker engineers, in turn, get to collaborate with customers and gain a better understanding of how customers use and want to use Looker.</p><p>We also like hosting hackathons because they’re fun, and we really enjoy seeing the impressive solutions attendees build in such a short time.</p><p>Our hope is that hackathon attendees get more enjoyment and benefit out of using Looker and that everyone learns more about the Looker API, the powerful integrations, and the numerous customizations that can be built on Looker.</p><h3>Improving Hackathon Processes With Looker</h3><p>As we learn from each Hackathon, we make iterative improvements. Since last May was only our second external Hackathon, we still have lots of room for process improvement. Our focus for the May event was to automate the registration and on-boarding experience for the Hackathon, all using Looker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-jF4nT1curyYO8uX" /><figcaption><em>A diagram of Looker’s Platform Architecture</em></figcaption></figure><p>Looker Hackathons are ultimately enabled by the <a href="https://looker.com/blog/why-a-data-platform">Looker Data Platform</a>. The Looker Data Platform enables our customers to extend <a href="https://looker.com/product/business-intelligence">Looker</a> and even build entirely new experiences on top of a unified and governed data model using our powerful APIs and SDKs.</p><p>Below are some enhancements to our Hackathon process that we built on top of Looker.</p><h4>Clustered Looker Hackathon Instances</h4><p>In the event attendees wanted to feel safe experimenting and playing with ideas beyond using their own instances, we set up multiple Looker instances (all configured identically) so projects could be developed against a “safe” Looker instance. To do this, we spun up multiple server instances based on what we created for last year’s Hackathon in San Francisco, updated with the latest version of Looker (6.12 at the time).</p><h4>Pre-loaded Datasets</h4><p>We made some fun and interesting datasets available to use on the playground instances:</p><ul><li><a href="https://looker.com/blog/create-your-own-game-of-thrones-data-visualizations">Game of Thrones</a>, a dataset with facts about actor screen time, scene details, and character deaths</li><li><a href="https://docs.looker.com/admin-options/system-activity">Looker System Activity</a>, an internal database and corresponding model that surfaces metadata about Looker instance usage</li><li>Reddit Comments, a dataset containing 1.7 billion Reddit comments from 2005–2019</li></ul><h4>Automated Welcome Email</h4><p>During preparations for our first Hackathon, we used the Looker admin UI on each Looker instance, which sent the attendee an email for each server containing a login link for that instance. This required a Looker admin to paste the list of emails for attendees into the “Add user” dialog and select a checkbox to send the email.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/0*t0BVTN0MAeNxel7R" /><figcaption><em>An example of the welcome email that all hackathon attendees received</em></figcaption></figure><p>We wanted to automate this a bit more for our May registration process. The day before the London Hackathon, we created a Python script using the Looker API and the SDK Code generator that:</p><ul><li>Reads user emails from a CSV file</li><li>Checks to see if the user is registered on each server</li><li>If the user is missing, the script:</li><li>Creates a new user</li><li>Gives the user appropriate development roles</li><li>Requests API keys for the user</li><li>Records their login URLs to a file, to share with each user</li></ul><p>If you’d like to do something similar, you can see the script at <a href="https://github.com/josephaxisa/hack_reg/blob/master/hack_reg.py">https://github.com/josephaxisa/hack_reg/blob/master/hack_reg.py</a>.</p><h4>Curating the Welcome Experience</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HtXZFqgyeCxigmsZ" /><figcaption><em>A custom Looker homepage we built to give developers inspiration and ideas for their hacks.</em></figcaption></figure><p>Another big focus for this hackathon was ensuring developers had a great Looker experience right from the start. With this in mind, we built a custom homepage for all of our Hackathon instances in Looker. This homepage — apart from looking super slick — helped address three critical questions that all developers have at Hackathons:</p><ul><li>What datasets can I use?</li><li>What have other folks already built?</li><li>What pre-existing resources can I build on?</li></ul><p>Our curated experience was able to answer these questions immediately so developers could get into the code faster.</p><h4>Judging the Hackathon</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vg0lMdRaoumk4Y5k" /><figcaption><em>Form that we built for Hackathon judges. The data from this form was linked to a table in BigQuery which was then connected to Looker.</em></figcaption></figure><p>To facilitate the judging of hacks and the presentation of awards, we created a Google form for the judges to fill out for each project. This form fed into a Google sheet, which then was analyzed by a Looker dashboard to show off the Best Hacks in real-time. Read about the Hackathon winners from the London Hack <a href="https://looker.com/blog/putting-the-hack-in-hackathon">here</a>.</p><h3>Pre-Hacks: Built on Looker</h3><p>In addition to the more custom-functionality that we built on top of Looker to power our hackathon, we promoted some cool, open-source developer tools that have been built on top of Looker to make developer experiences easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CfztsWBsz_s-eLn7" /><figcaption><em>Scott Sirowy presenting the Hackathon overview to attendees</em></figcaption></figure><h4>SDK Codegen</h4><p>Looker provides some pre-packaged client language SDKs for specific languages, including <a href="https://github.com/looker/lookr">R</a> and <a href="https://docs.looker.com/reference/api-and-integration/api-sdk">Ruby</a>. For language/platform SDKs not currently provided by Looker, the new <a href="https://github.com/looker-open-source/sdk_codegen">SDK Codegen</a> project provides an easy way to generate an SDK in a developer’s desired language. During the London Hackathon, a few different teams used this SDK codegen to generate an SDK for their preferred development language.</p><p>This <a href="https://looker-open-source.github.io/">open-source project</a> also supports a command to serve up <a href="https://docs.looker.com/reference/api-and-integration/api-getting-started#interactive_api_documentation_and_explorer">a local interactive UI</a> to quickly search the API specification for any text and immediately find the functions containing the search value.</p><h4>Looker’s Embed SDK</h4><p>One of the hack projects in London leveraged the newly available <a href="https://www.npmjs.com/package/@looker/embed-sdk">Embed SDK</a>, which makes it easier to embed Looker in your own web app. This SDK simplifies the creation of, and communication with, Looker visual elements embedded in another web site. The <a href="https://github.com/looker-open-source/embed-sdk">open-source repository</a> also includes some demonstration code.</p><h4>Looker Visualization Builder</h4><p>Out of the box, Looker ships with a number of configurable visualizations to bring your data to life. While those visualizations cover a number of common use cases, they don’t cover everything. To that end, customers often build their own <a href="https://looker.com/platform/blocks/directory#viz">custom visualizations</a> using the <a href="https://github.com/looker/custom_visualizations_v2">custom visualization API</a> that can seamlessly integrate with your explores and dashboards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Rv0Sb1zYqQ8egatQ" /><figcaption><em>Looker Custom Visualization Builder we developed for the London Hackathon</em></figcaption></figure><p>To make it even easier for our Hackathoners, we built a <a href="https://lookervisbuilder.com/">Codepen-like playground</a> to facilitate the creation of new custom visualizations. The playground provided sample data, hooks, and a more real-world environment for our customers’ visualizations to interact with during development.</p><h3>London Hacks Looker</h3><p>Armed with twelve hours, plenty of food and drink, and an additional appetite to build something novel on top of Looker, London was ready to hack!</p><h4>Break it down</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Saip05z97u8whyrs" /><figcaption><em>Handstands: A stretch goal</em></figcaption></figure><p>The hackathon wasn’t all fun and games — we also took some time to recharge. For our afternoon break, Scott led willing participants in a stretching and handstand session to reawaken their bodies. While many participated in the stretching portion, only Scott did a handstand at the end.</p><p>We now have a stretch goal for the next Hackathon — get at least one more person to safely attempt a handstand!</p><h4>Quick Hack — Star Ratings</h4><p>One of the sample datasets available on the Hackathon instances is Amazon Product Reviews. In the screenshot below, a quick hack by one of the London Hackathoners shows a <strong>Star Rating Vis</strong> column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jNTrwvKQiQAv6Y1P" /><figcaption><em>Star Ratings Functionality by Simon Clark (The Analytics Academy)</em></figcaption></figure><pre>measure: average_star_rating_vis {<br>  type: number<br>  sql: ${average_star_rating} ;;<br>  html:<br>    &lt;span style=&quot;text-align: left&quot;&gt;<br>      {% for i in (1..value) %}<br>        ⭐️<br>      {% endfor %}<br>    &lt;/span&gt;<br>  ;;<br>}</pre><h3>What’s next?</h3><p>We’ve had a blast hosting and helping out at our first two Hackathons. The projects completed have both impressed and inspired us, and have encouraged us to host many more of these events in the future.</p><p>Our next scheduled Hackathon is on November 4th, 2019 in San Francisco, coinciding with <a href="https://looker.com/events/join-2019">JOIN 2019</a>. We look forward to sharing more updates about this and future Looker hackathons and hope to see you in attendance at one in the near future!</p><p>Want to have a Hackathon near you? <a href="/service/mailto:developers@looker.com">Tell us!</a></p><p><em>Curious to learn more about our Looker team? Check out our </em><a href="https://looker.com/company/careers?utm_campaign=7012R000001JEEM&amp;utm_source=other&amp;utm_medium=other&amp;utm_content=other"><em>open positions</em></a><em>!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e902f761acd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/looker-engineering/looker-hack-london-4e902f761acd">Engineering a Hackathon with Looker</a> was originally published in <a href="https://medium.com/looker-engineering">Looker Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iFrame Sandbox Permissions Tutorial]]></title>
            <link>https://medium.com/looker-engineering/iframe-sandbox-security-3cb246eacb0d?source=rss----b74412cf1aff---4</link>
            <guid isPermaLink="false">https://medium.com/p/3cb246eacb0d</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[sandbox]]></category>
            <category><![CDATA[iframe]]></category>
            <dc:creator><![CDATA[Jim Rottinger]]></dc:creator>
            <pubDate>Fri, 03 May 2019 13:01:01 GMT</pubDate>
            <atom:updated>2019-05-03T13:01:00.955Z</atom:updated>
            <content:encoded><![CDATA[<h4>A guided walkthrough of restricting iframe permissions using the sandbox property</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U5-omxBEI1XZUi7VB5Ajvg.png" /></figure><h3><strong>Understanding iFrame Sandboxes and iFrame Security</strong></h3><p>Embedding third-party JavaScript in web applications is a tale as old as time. Whether it’s dropping a widget onto your web page or including custom content from a client in your cloud application, it’s something that many developers have encountered in their career. We all know about the iframe element in HTML, but how much do we really know about how it works? What are the security concerns associated with running code inside of an iframe and, furthermore, how can the HTML5 sandbox attribute on the frame alleviate these concerns?</p><p><strong>The goal of this tutorial is to walk through the various security risks associated with running third-party JavaScript on your page and explain how sandboxed iframes can alleviate those issues by restricting the permissions it is allowed to run with.</strong></p><p>In this post, we’ll demonstrate setting up a demo application from the ground up that will simulate running JavaScript coming from a different origin. What we should end up with is a sandboxed environment in which we can execute any arbitrary JavaScript and still sleep well at night, knowing our host application will be safe from harm.</p><p>With all of that in mind, the guided walkthrough will consist of the following parts:</p><ol><li>Setting up two node servers to simulate two different origins</li><li>Embedding the content of our client page in an iframe on the host page and investigating what the client iframe is and is not allowed to do</li><li>Applying the sandbox attribute to the iframe and exploring the various options for the sandbox.</li></ol><p>Let’s get started!</p><h3>Step 1: Setting up the Servers for our Demo Application</h3><p>To simulate executing code from a different origin, we are going to set up two node servers — one which we’ll call the <em>host</em> and second which we will call the <em>client</em>. We can do this using node’s http library to listen to and serve from two different ports.</p><pre>// server.js<br>const http = require(&#39;http&#39;);</pre><pre>const hostname = &#39;localhost&#39;;<br>const host_port = 8000;<br>const client_port = 8001;</pre><pre>const host_server = http.createServer((req, res) =&gt; {<br>  res.statusCode = 200;<br>  res.setHeader(&#39;Content-Type&#39;, &#39;text/plain&#39;);<br>  res.end(&#39;This is the Host Server\n&#39;);<br>}).listen(host_port, hostname, () =&gt; {<br>  console.log(`Server running at <a href="http://${hostname}:${host_port}/`">http://${hostname}:${host_port}/`</a>);<br>});;</pre><pre>const client_server = http.createServer((req, res) =&gt; {<br>  res.statusCode = 200;<br>  res.setHeader(&#39;Content-Type&#39;, &#39;text/plain&#39;);<br>  res.end(&#39;This is the Client Server\n&#39;);<br>}).listen(client_port, hostname, () =&gt; {<br>  console.log(`Client running at <a href="http://${hostname}:${client_port}/`">http://${hostname}:${client_port}/`</a>);<br>});;</pre><p>Save this JS file to whatever name you’d like — I called it server.js. Then, to start our server, we can simply run:</p><pre>node server.js</pre><p>This should start two different http servers, one on port 8000 and the second on port 8001. To test that it is working, you can individually visit your localhost on port 8000 and 80001, which should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*Ryzh7vDV9VBbdN4Ozkj1cQ.png" /><figcaption>Two node servers running on two different ports</figcaption></figure><p>Even though they are both running on localhost, <strong>the </strong><a href="https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy"><strong>same-origin policy</strong></a><strong> that browsers implement operate on a protocol-host-port tuple that will only be true if the protocol, the hostname, and port number all match up.</strong> In this case, the protocol and host are the same, but since the ports are different, these will be considered to be different origins.</p><p>Of course, just having a hard-coded response won’t get us very far. We’ll need to be able to serve both HTML and JS for this demo. To do this, I whipped up a function to serve assets from a given folder.</p><pre>function serveAsset(rootPath, url, res) {<br>  // default root route to index.html in the folder<br>  if (url === &#39;/&#39;) url = &#39;index.html&#39;;</pre><pre>  const filePath = path.join(__dirname, rootPath, url)<br>  const readStream = fileSystem.createReadStream(filePath)<br>    .on(&#39;error&#39;, function() {<br>      res.statusCode = 404;<br>      res.end();<br>    });</pre><pre>  if (/^.*\.js$/.test(url)) {<br>    res.setHeader(&#39;Content-Type&#39;, &#39;text/javascript&#39;);<br>  } else {<br>    res.setHeader(&#39;Content-Type&#39;, &#39;text/html&#39;);<br>  }</pre><pre>  readStream.pipe(res);<br>}</pre><p>This function will take in a root folder path, a url, and the response object. If the file is not found, it will return 404 and, if it is found, it will set the header to be text/javascript or text/html depending on the file suffix. To get this to work, we need to include two more dependencies at the top of the file:</p><pre>const fileSystem = require(&#39;fs&#39;);<br>const path = require(&#39;path&#39;);</pre><p><strong>Fun fact </strong><em>— </em>Since we’re just using built-in node libraries, we do not have to install anything via npm! Once you instantiate fileSystem, path, and our asset function, go ahead and update your servers as well to call serveAsset.</p><pre>const host_server = http.createServer((req, res) =&gt; {<br>  serveAsset(&#39;host&#39;, req.url, res)<br>}).listen(host_port, hostname, () =&gt; {<br>  console.log(`Server running at <a href="http://${hostname}:${host_port}/`">http://${hostname}:${host_port}/`</a>);<br>});;</pre><pre>const client_server = http.createServer((req, res) =&gt; {<br>  serveAsset(&#39;client&#39;, req.url, res)<br>}).listen(client_port, hostname, () =&gt; {<br>  console.log(`Client running at <a href="http://${hostname}:${client_port}/`">http://${hostname}:${client_port}/`</a>);<br>});</pre><p>These now look very similar. The only difference is that the host_server will look for its assets in the host folder and the client_server will look in the client folder. If we were to restart our server now, we would see the following error message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*n4YAIkIHxfyFA3igZi7ECg.png" /></figure><p>This is because our serveAsset function is looking in either the host or client folder for an asset to serve, and we haven’t created them yet! Let’s create both of them, each with an index.html and a JS file.</p><pre>» mkdir host; mkdir client; touch host/index.html; touch host/host.js; touch client/index.html; touch client/client.js</pre><p>Our file structure should look like this:</p><pre>[-]host<br>  index.html<br>  host.js</pre><pre>[-]client<br>  index.html<br>  client.js</pre><pre>server.js</pre><p>Now, if we start our server and visit our localhost, we no longer get the 404, which means our server found the file! — but it has no content yet. To get some content in, let’s start with something very simple. For the host, we simply have the HTML as:</p><pre>&lt;!-- index.html --&gt;<br>&lt;html&gt;<br>  &lt;head&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;h1&gt;Host Page&lt;/h1&gt;<br>    &lt;p&gt;Host message container&lt;/p&gt;</pre><pre>    &lt;script type=&quot;text/javascript&quot; src=&quot;host.js&quot;&gt;&lt;/script&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>And the JavaScript as:</p><pre>alert(&#39;hello from the host&#39;)</pre><p>The client content is exactly the same, just with the word host changed to client.</p><p>If we restart our server now, we should be able to go to both <a href="http://localhost:8000/">http://localhost:8000/</a> and<a href="http://localhost:8001/"> http://localhost:8001/</a> and see our content in action! Each page should send an alert from the JS file and then render our html content to the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*Hw1CDwUO3ikmUNJsimTtpg.png" /><figcaption>Each node server is serving an index.html file which includes a JavaScript file</figcaption></figure><h3>Step 2: Embedding the Client in the Host without Sandboxing and Investigating its Permissions</h3><p>With our two servers running, we are now ready to begin testing some iframe scenarios. Before we do that, let’s add a second file to our host so that we can compare the permissions of an iframe from the same origin and an iframe from a different origin.</p><pre>touch host/hosted-client.html; touch host/hosted-client.js</pre><p>Fill in the content of these files with the same content as we used for our other html/JS pairs. We’ll call this one the “Hosted Client,” meaning an iframe client coming from the same origin as our host.</p><p>Once we do that, back in our host/index.html we can iframe both our same-origin client and our different-origin client.</p><pre>&lt;iframe width=400 height=300 src=&quot;<a href="http://localhost:8000/hosted-client.html">http://localhost:8000/hosted-client.html</a>&quot;&gt;&lt;/iframe&gt;<br>&lt;iframe width=400 height=300 src=&quot;<a href="http://localhost:8001/index.html">http://127.0.0.1:8001/index.html</a>&quot;&gt;&lt;/iframe&gt;</pre><p><strong>Please note</strong> that we use localhost for the hosted-client and 127.0.0.1 for the other. This will become important in the cookies section below. Refreshing the host page, you should now see two iframes, each with the content of our individual HTML files.</p><p>If you have alerts in your JS files like I do, you should have seen that each individual file triggers an alert at the top level of the browser. Should it be able to do this? That question brings us to our first area of concern — pop-ups and dialog boxes.</p><h4>Pop-ups and Dialog Boxes</h4><p>JavaScript has three different functions that trigger a popup — alert, prompt, and confirm. Each of these open up a dialog box at the top of the browsing context, regardless of whether it comes from the top-level window or not. The scary thing about these dialogs, as can be found in the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/alert">alert documentation</a>, is:</p><blockquote>Dialog boxes are modal windows — they prevent the user from accessing the rest of the program’s interface until the dialog box is closed. For this reason, you should not overuse any function that creates a dialog box (or modal window).</blockquote><p>I am sure that most of you have, at some point in your life, been forcefully redirected to a spammy site against your will that then bombarded you with these types of dialogs. Even when you try to close out of it, it just pops open another one. This annoying behavior completely blocks you out of using a site and sadly, it’s incredibly simple to reproduce. Try adding this to your client.js file:</p><pre>(function unescapablePrompt() {<br>  if (window.confirm(&quot;Do you want to win $1000?!?!&quot;)) {<br>    /* Open some spammy webpage or redirect */<br>    unescapablePrompt()<br>  } else {<br>    unescapablePrompt()<br>  }<br>}());</pre><p>Now, when you visit your host site, you get this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*49r9B9EVd-BEh3vrN2GiqA.gif" /></figure><p>These prompts make it impossible to ever interact with the page and you have to close the entire tab or kill the JavaScript execution to get rid of it. <strong>The worst part is that regardless of whether your embedded content is coming from a different host or the same origin, this behavior is exploitable.</strong></p><p>You might think that you could just do something like this to get rid of it:</p><pre>alert = prompt = confirm = function () { } // does not work!</pre><p>The problem with this is that each iframe operates within its own nested browsing context, so overriding the functions at the host level will not affect the functions at the frame level.</p><p>Fortunately, sandboxing can come to our rescue here, which we will see later in this post. For now, let’s move on to whether or not the iframe can navigate the page away from the current one.</p><h3>Step 3: Top-level Window Navigation and Opening New Tabs</h3><p>Let’s now examine how and if the iframes are able to change the url of the top-level window and if they’re able to open a new window.</p><p>There are two different methods that we want to test here.</p><ol><li><strong>window.open</strong> for opening new windows and tabs, and</li><li><strong>window.location</strong> for navigating the page away from the current url.</li></ol><p><strong>Helpful Note</strong> — iframes can reference its top-level window using window.top. Similarly, it can reference its parent’s window with window.parent. In our case, they do the same thing.</p><p>Let’s remove all the code in client.js and replace it with:</p><pre>window.top.location = &#39;<a href="http://localhost:8001&#39;">http://localhost:8001&#39;</a></pre><p>This will attempt to redirect the top-level window to the client host. If we run this, we get the following error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*koiRgrCGNOBcgMwybEwhPQ.png" /><figcaption>Error received when trying to navigate the top-level window from within an iframe</figcaption></figure><p>That’s great! It blocks the automatic redirect. But wait — what’s that last part? “… nor has it received a user gesture.” What does that mean? Does it mean that a user-initiated gesture can navigate the window? Let’s try it.</p><pre>// client.js<br>function clickNav () {<br>  window.top.location = &#39;<a href="http://localhost:8001&#39;">http://localhost:8001&#39;</a><br>}</pre><pre>// client/index.html<br>&lt;a href=&quot;&quot; onclick=&quot;clickNav()&quot;&gt;Navigate me&lt;/a&gt;</pre><p>If we add this code to our JS and HTML respectively, it will add a link to the client page. When we click it, the page navigates!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*M49WtCvFCIfrMtx5U6zvTA.gif" /><figcaption>A user-initiated action can navigate the page from an iframe. This is the basics behind clickjacking</figcaption></figure><p>As it turns out, a user-initiated action can navigate the top-level window. This is basic idea behind <a href="https://www.owasp.org/index.php/Clickjacking"><strong>clickjacking</strong></a><strong>. </strong>A typical clickjacking attack will put transparent click boxes over a page and then “hijack” the click to redirect the page to a different url. window.open works the same way.</p><pre>// client.js<br>function clickNav () {<br>  window.open(&#39;<a href="http://localhost:8001&#39;">http://localhost:8001&#39;</a>)<br>}<br>window.open(&#39;<a href="http://localhost:8001&#39;">http://localhost:8001&#39;</a>)</pre><p>If we have this, the browser will block the pop-up request of the outer function call, however, when we have it in a click handler, it will open the window regardless of whether we blocked pop-ups or not.</p><p>The other part of the above error message saying the iframe “does not have the same origin as the window it is targeting” means our iframe is the same origin as the host and it has full access to redirect the page, click-action or not.</p><pre>// hosted-client.js<br>window.top.location = &#39;<a href="http://localhost:8001&#39;">http://localhost:8001&#39;</a></pre><p>If you run this, the browser will allow the redirect to happen since it is the same origin. This is not the case for window.open. Even if it is from the same origin, the browser will block the window.open unless you explicitly tell the browser to allow the pop-up.</p><h4>Cookies and Browser Requests</h4><p>The final thing we are going to look at is browser cookies. Before getting started, make sure your hosted-client iframe is pointed at localhost and your client.js iframe is pointed at 127.0.0.1.</p><pre>&lt;iframe width=400 height=300 src=&quot;<a href="http://localhost:8000/hosted-client.html">http://localhost:8000/hosted-client.html</a>&quot;&gt;&lt;/iframe&gt;<br>&lt;iframe width=400 height=300 src=&quot;<a href="http://127.0.0.1:8001/index.html">http://127.0.0.1:8001/index.html</a>&quot;&gt;&lt;/iframe&gt;</pre><p>We need to do this because cookies care about domain and ignore the port. Once you have checked this, let’s set a cookie on the host.</p><pre>// host.js<br>document.cookie = &quot;session_id=A38XJISDASDW120&quot;</pre><p>This is representing a session ID, something that is often included in requests. Let’s see if our iframes can access the cookies.</p><pre>// in client.js<br>console.log(document.cookie) // &quot;&quot;</pre><pre>// in hosted-client.js<br>console.log(document.cookie) // session_id=A38XJISDASDW120</pre><p>As you can see, the client cannot access the cookies since it is a different origin, but the hosted-client can. Let’s try to make a request using the fetch API.</p><pre>// hosted-client.js<br>var myRequest = new Request(&#39;<a href="http://localhost:8000&#39;">http://localhost:8000&#39;</a>);</pre><pre>fetch(myRequest, {<br>  method: &#39;GET&#39;,<br>  credentials: &quot;include&quot;<br>}).then(function(response) {<br>  console.log(response)<br>});</pre><p>When we do this, we get a 200 response.</p><pre>Response {type: &quot;basic&quot;, url: &quot;<a href="http://localhost:8000/">http://localhost:8000/</a>&quot;, redirected: false, status: 200, ok: true, …}</pre><p>That means the server accepted the request and gave us a response, but did it send through the cookies? We can can check that on the server side. Let’s add a console log to our host server request handler.</p><pre>const host_server = http.createServer((req, res) =&gt; {<br>  console.log(req.headers)<br>  serveAsset(&#39;host&#39;, req.url, res)<br>}).listen(host_port, hostname, () =&gt; {<br>  console.log(`Server running at <a href="http://${hostname}:${host_port}/`">http://${hostname}:${host_port}/`</a>);<br>})</pre><p>This will output the headers when we make a request to our host server. Make sure you restart the server after you add this line, and then reload your page and look for the request coming from the hosted-client. It looks like this:</p><pre>{ <br>  host: &#39;localhost:8000&#39;,<br>  connection: &#39;keep-alive&#39;,<br>  &#39;user-agent&#39;: &#39;Mozilla/5.0 (Macintosh......&#39;,<br>  accept: &#39;*/*&#39;,<br>  referer: &#39;<a href="http://localhost:8000/hosted-client.html&#39;">http://localhost:8000/hosted-client.html&#39;</a>,<br>  &#39;accept-encoding&#39;: &#39;gzip, deflate, br&#39;,<br>  &#39;accept-language&#39;: &#39;en-US,en;q=0.9&#39;,<br>  cookie: &#39;session_id=A38XJISDASDW120&#39;<br>}</pre><p>As you can see, it sends the cookies through. If the server were to use just the session ID to authenticate the request, then it would think this is a legitimate request.</p><h3>Step 4: Applying the Sandbox Attribute to the Iframe</h3><p>So far, we’ve identified four areas of concern when working with iframes.</p><ol><li>They can exploit pop-up dialog boxes to prevent interaction with the website</li><li>Navigating the top-level window through clickjacking even on different-origin iframes</li><li>Navigating the top-level window when the origin is the same even without user interaction</li><li>Same-origin iframes can make requests with cookies.</li></ol><p>Now we’re going to begin making use of the sandbox attribute for iframes, introduced in HTML5. When added to an iframe, the sandboxed iframe restricts pretty much all scripts and browser behavior of any kind. It is not until we add the permissions in a space-separated list that we enable the exact permissions we want to set. To see its initial state, add the attribute as an empty string to both of our iframes.</p><pre>&lt;iframe sandbox=&quot;&quot; width=400 height=300 src=&quot;<a href="http://localhost:8000/hosted-client.html">http://localhost:8000/hosted-client.html</a>&quot;&gt;&lt;/iframe&gt;<br>&lt;iframe sandbox=&quot;&quot; width=400 height=300 src=&quot;<a href="http://127.0.0.1:8001/index.html">http://127.0.0.1:8001/index.html</a>&quot;&gt;&lt;/iframe&gt;</pre><p>When we sandbox the iframe, it blocks all scripts from executing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x8-HTDAaa5cvo5WfQHZAFA.png" /><figcaption>Sandboxed iframes with no permissions block all scripts from running</figcaption></figure><p>Getting this to work starts by allowing various permissions one at a time . The full list of string values can be found in the<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe"> iframe documentation</a> under the sandbox section. We will be starting with allow-scripts.</p><h4>Allowing Scripts</h4><p>To begin here, let’s clear out our client.js and hosted-client.js and start with a simple console log.</p><pre>console.log(&quot;I executed!&quot;)</pre><p>Without defining any permissions, our sandbox won’t allow a console log to run. We can get our script running by adding the allow-scripts permission to our iframe attribute.</p><pre>sandbox=&quot;allow-scripts&quot;</pre><p>Once you do this, and refresh the page, you should see a console log from each of our pages.</p><h4>Pop-ups and Modals</h4><p>One of the concerns we learned about is that an iframe can pop up dialog boxes at the top of the browsing context and prevent the user from interacting with the page. To see if this is exploitable in a sandbox, let’s add an alert to our client script.</p><pre>alert(&quot;hello from the client&quot;)</pre><p>When we run that we get the following error:</p><pre>“Ignored call to ‘alert()’. The document is sandboxed, and the ‘allow-modals’ keyword is not set.”</pre><p>Even though we are allowing scripts to run, the sandbox still limits a lot of the behavior. In order for the alert to work from the iframe, we would have to add the allow-modals property to the iframe.</p><pre>sandbox=&quot;allow-scripts allow-modals&quot;</pre><p>Keep in mind that this is an all-or-nothing thing. We cannot allow some popups and block others. That is in okay restriction, in my opinion, and crosses off our first iframe security concern.</p><h4>Top-level Window Navigation and Opening New Tabs</h4><p>Our second and third security concerns are related to navigating the page away from the original URL. We saw that a same-origin iframe could navigate the page without a user interaction, and that a different-origin iframe could do so with user interaction. Let’s try this in our sandbox.</p><pre>// client.js<br>function clickNav () {<br>  window.top.location = &#39;<a href="http://localhost:8001&#39;">http://localhost:8001&#39;</a><br>}<br>window.top.location = &#39;<a href="http://localhost:8001&#39;">http://localhost:8001&#39;</a></pre><p>This results in the follow errors:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*VoufDVMjUflEsfcxJD2rtg.png" /><figcaption>An iframed sandbox cannot navigate the page, with or without user-interaction</figcaption></figure><p>We covered two cases at once here. The initial command to change the location failed, as did the one on-click. There are actually separate permissions we can apply to our iframe for each of these cases. We can allow any navigation with allow-top-navigation and user-activated navigation with allow-top-navigation-by-user-activation.</p><pre>sandbox=&quot;allow-scripts allow-top-navigation-by-user-activation&quot;</pre><p>When we turn this on, the different-origin iframe can redirect the page upon user action. The case is the same for same-origin iframes, where you can explicitly set the navigation permissions, regardless of the origin.</p><h4>Cookies and Browser Requests</h4><p>The final concern to address is the ability to access cookies and make requests with same-origin iframes. Let’s try accessing the cookies with a sandboxed iframe.</p><pre>// hosted-client.js<br>console.log(document.cookie)</pre><p>Unlike last time, this results in the following error:</p><pre>Uncaught DOMException: Failed to read the &#39;cookie&#39; property from &#39;Document&#39;: The document is sandboxed and lacks the &#39;allow-same-origin&#39; flag.</pre><p>Similarly, when we try to make a request with the same request code as the previous section, we get a different error.</p><pre>Failed to load <a href="http://localhost:8000/">http://localhost:8000/</a>: No &#39;Access-Control-Allow-Origin&#39; header is present on the requested resource. Origin &#39;null&#39; is therefore not allowed access. If an opaque response serves your needs, set the request&#39;s mode to &#39;no-cors&#39; to fetch the resource with CORS disabled.</pre><p>The above error is the browser blocking our request because we no longer have the same origin. This is because the <strong>sandbox property sets the origin of the frame to </strong><strong>null</strong>, meaning it will now be a cross-origin request, even though the iframe is hosted on the same domain.</p><p>Adding the allow-same-origin sandbox attribute will prevent both of these errors from occurring. However, you should be careful and make sure you have complete control over the content of the frame before using it. As noted in the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe">Mozilla iframe documentation</a>:</p><blockquote>When the embedded document has the same origin as the main page, it is strongly discouraged to use both allow-scripts and allow-same-origin at the same time, as that allows the embedded document to programmatically remove the sandbox attribute. Although it is accepted, this case is no more secure than not using the sandboxattribute.</blockquote><p>Generally speaking, if you find yourself needing both allow-scripts and allow-same-origin for your sandbox, you should ask yourself why you are iframing in the first place and whether or not having the sandbox property is appropriate.</p><h3><strong>Putting It All Together: How We Use iframes at Looker</strong></h3><p>As an example of a practical use of this, here at Looker, we use iframes to allow customers to create and run their own custom visualizations within our application.</p><p>Without any one way to vet every single line of code our customers could write for their custom visualizations, we needed to create a secure execution environment to run the code in. A diagram of this environment can be seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Azz4aouCOh79x1Mi" /><figcaption><em>Looker explore page using an iframe to render custom data visualization</em></figcaption></figure><p>We leverage the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage">postMessage API</a> to pass the data in and to receive back any events or errors that the visualization produces. Given the restrictions of the sandboxed iframe, it is not able to make calls outside of its own frame, nor is it able to read or modify anything about the parent page. This let’s us rest assured that both our application and our customers’ data is safe and secure.</p><h3>Wrapping Up</h3><p>I hope you found this post helpful as you address security concerns related to sandboxed iframes. By walking through this tutorial, you should now have a better understanding of:</p><ul><li>How sandboxed iframes with the allow-modals permission can potentially prevent user interaction on the page</li><li>How sandboxed iframes without the allow-top-navigation or the allow-top-navigation-by-user-activation properties can alleviate same-origin iframes that can redirect the top-level page, as well as different-origin iframes with some user interaction.</li><li>Why sandboxed iframes without the allow-same-origin property prevent same-origin iframes from having access to the domain’s cookies and making requests as if they were the host.</li></ul><p>If you have any questions about this tutorial, feel free to reach out on the <a href="https://discourse.looker.com/">Looker Community</a>. And if you’re curious to learn more about our Looker team, check out our <a href="https://looker.com/company/careers?utm_campaign=7012R000001JEEM&amp;utm_source=other&amp;utm_medium=other&amp;utm_content=other">open positions</a>.</p><p><strong>Important Notes</strong></p><ul><li>Although sandboxing is very powerful for security, don’t put all of your security eggs in the sandbox basket, as it is<a href="https://caniuse.com/#feat=iframe-sandbox"> not supported by IE9 and below.</a></li><li>If you struggled with any part of this tutorial, all of the code can be found in the<a href="https://github.com/JimRottinger/sandbox_sandbox"> sandbox-sandbox repository</a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cb246eacb0d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/looker-engineering/iframe-sandbox-security-3cb246eacb0d">iFrame Sandbox Permissions Tutorial</a> was originally published in <a href="https://medium.com/looker-engineering">Looker Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>