<?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[Stories by Alexander Minozhenko on Medium]]></title>
        <description><![CDATA[Stories by Alexander Minozhenko on Medium]]></description>
        <link>https://medium.com/@minozhenko?source=rss-13b50555476a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*vNqau09ZHfKq5fYy.</url>
            <title>Stories by Alexander Minozhenko on Medium</title>
            <link>https://medium.com/@minozhenko?source=rss-13b50555476a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 23:29:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@minozhenko/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Content Security Policy for Webpack]]></title>
            <link>https://medium.com/@minozhenko/content-security-policy-for-webpack-b4d1dd305feb?source=rss-13b50555476a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4d1dd305feb</guid>
            <category><![CDATA[web-application-security]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[appsec]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Alexander Minozhenko]]></dc:creator>
            <pubDate>Sun, 17 Sep 2017 01:47:31 GMT</pubDate>
            <atom:updated>2017-09-17T01:53:39.671Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to implement CSP in static web applications</h4><p>One of the most common vulnerability is Cross-Site Scripting. It’s fundamental flaw of the web, since there is no way for a browser to distinguish between trusted html elements and malicious javascript. But there is solution for this problem and it’s<a href="https://www.w3.org/TR/CSP/"> Content Security Policy</a>.</p><p>Content Security Policy(CSP) allows a web server to tell a browser which elements are allowed and everything else is blocked by default. Therefore working as an integrity check for a html page and preventing any modification of the page by third party.</p><p>The recommended way to use CSP is <a href="https://csp.withgoogle.com/docs/strict-csp.html">Strict CSP</a> approach. It uses the nonce attribute and the strict-dynamic attribute. There are some frameworks which helps to enable Content Security Policy, like <a href="https://developers.google.com/closure/templates/">Closure Templates</a> which adds nonce attribute in script element or <a href="https://github.com/mozilla/django-csp">django-csp</a> module which adds CSP header. But this will not work if you have a static single page application and can not generate random nonce on every request or don’t even have a web server to add a HTTP header. For example, an electron application or modern single page application, which only have index.html.</p><h4>CSP for a Single Page Web Application</h4><p>For static single page web applications the better way to do Content Security Policy would be to use hashes instead of nonce and have CSP policy in meta tag rather then in HTTP header. This webpack plugin can help with it</p><p><a href="https://bitbucket.org/atlassianlabs/csp-webpack-plugin">atlassianlabs / csp-webpack-plugin</a></p><p>It uses the webpack module bundler which became standard de facto in client side development and HTMLWebpackPlugin plugin which also widely used.</p><p>To use it you just need this code in your webpack.config</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/379944056f16c021c2444767dc5a8202/href">https://medium.com/media/379944056f16c021c2444767dc5a8202/href</a></iframe><p>and put the placeholder index.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc236a21782889fa7e0f17da4becfc32/href">https://medium.com/media/bc236a21782889fa7e0f17da4becfc32/href</a></iframe><p>It will generate the CSP like that on every build</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f9a8f66ed8eb25b3ba26e82e89d2e85/href">https://medium.com/media/9f9a8f66ed8eb25b3ba26e82e89d2e85/href</a></iframe><h4>Conclusion</h4><p>Advantages of this approach are:</p><ul><li>make it much easier to deploy CSP compare to nonce based approach. CSP generated during a build stage and then can be put on a cdn or packaged with an electron application.</li><li>No performance impact since it’s only generated once.</li><li>Can be combined with SubResource Integrity for external scripts, but this is not yet supported by browsers.</li></ul><p>But there also some disadvantages:</p><ul><li>We need to use whitelist for external scripts.</li><li>We can not have CSP in report mode or use the “iframe-ancestor” directive if CSP deployed in meta tag. Therefore much less visibility and protection.</li></ul><p>CSP provides a great mitigation against XSS attacks and it should be deployed on every web application even if it’s static single page web application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4d1dd305feb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>