{"id":109,"date":"2015-11-22T23:01:44","date_gmt":"2015-11-22T23:01:44","guid":{"rendered":"http:\/\/www.ilovesecure.com\/?p=109"},"modified":"2020-07-21T21:43:05","modified_gmt":"2020-07-21T21:43:05","slug":"protect-your-site-from-malvertising-tracking-code-iframes","status":"publish","type":"post","link":"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/","title":{"rendered":"Protect your site from malvertising and bad tracking codes"},"content":{"rendered":"<p>Your pages and your site are exposed to became the container of malicious code, code somebody placed in your page without your approval. You include code from outside, because you need advertising and tracking codes, but these elements are out of your control. Malvertising and bad tracking codes are ready to take control of your pages.<br \/>\nSuch front end code (JavaScript, Flash, etc) can manipulate the content of your page, read data present in the form users are editing, collect these information and send somewhere else. Taking advantage of vulnerabilities present in browser plugins, this code injected in your site pages could even be able to install specific malware into user PC.<br \/>\nBeing a front end manipulation often site managers have no visibility on what is happening, only the end user browser is affected.<br \/>\nBut when emails, credit card numbers and other personal information are moved to someone else without the explicit approval of the user due to malicious code in your pages, this is a legal responsibility of site owner and he can be persecuted even if he is a victim as the end user.<\/p>\n<p>IMPORTANT: the term &#8220;malvertising&#8221; is mostly referred to an advertising banner able to install a malicious software, called malware, in the user PC. Here we will focus on advertising able to interact with your page, stealing data such as username, password, credit card numbers.<\/p>\n<h2>How this malicious code can be placed in your pages:<\/h2>\n<p><strong>1) because of your developers or content editors:<\/strong> for a mistake or an infected pc, somebody allowed to change your site place some malicious code inside your pages. It is a quite rare, but the examples of infected pc involuntary able to included\u00a0 external malicious JavaScript are present in security literature.<br \/>\n<strong>2) because the page is not well designed it can be exposed to cross site scripting:<\/strong> somebody can inject runtime JavaScript code using a specifically designed url. So I can send by email a link to a regular official page of yours with special parameters and when your page is opened, it contains some malicious code. Check pages against cross site scripting is quite simple, just use some standard penetration test application.<br \/>\n<strong>3) because the page include some tag like advertising, tracking code, external content:<\/strong> these tags are usually a chain of &#8220;include&#8221; very complex and the owner of the site is never able to control what is really coming inside his pages. You include a tag provided by your adv server then, when executed, this piece of code include other scripts coming from other sources and so on. Some adv servers are quite strict in control, but the biggest part are quite easy to be tricked. This malicious advertising is called malvertising, and it is one of the most critical point in secure your pages.<\/p>\n<div id=\"attachment_124\" style=\"width: 910px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-124\" class=\"wp-image-124 size-large\" src=\"https:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising-1024x417.png\" alt=\"include malware and bad tracking codes\" width=\"900\" height=\"367\" srcset=\"https:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising-1024x417.png 1024w, https:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising-300x122.png 300w, https:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising.png 1234w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/a><p id=\"caption-attachment-124\" class=\"wp-caption-text\">process to include malware and bad tracking codes<\/p><\/div>\n<p>We will focus on this 3rd case: insecure advertising, insecure tracking codes, not controlled external content.<\/p>\n<h2>What malvertising and bad tracking codes can do:<\/h2>\n<p>In the worse cases a marvertising is able to install a malware directly into the client PC just when an advertising banner appears on the page, without any active action done by the user. This is usually done taking advantage of vulnerabilities of browser plugin. In this case only a good antivirus and a good antimalware can help the client PC to be protected (we will speak in the future more in deep regarding these issues).<br \/>\nWhat an antivirus \/ antimalware can not block is the interaction between script in your pages and your page content. As described before, these front end codes included from outside can:<br \/>\n1) they can read all the parameters arriving to your page and send them away<br \/>\n2) they can read all parameters, text fields, passwords, credits card numbers present in the page and send them away<br \/>\n3) they can redirect your page to any other site<br \/>\n4) they can change the content of your page<br \/>\n5) they can use your page, and your customers, as attach vehicle to other site<\/p>\n<h2>What can you do to protect your site from malvertising and bad tracking codes?<\/h2>\n<p>Assume we review the code before any deploy and we protect our page from cross site scripting. This means we need to protect our pages only from malicious code coming through advertising, tracking code or any included content. These kind of components can not be secured by design or with architectural solutions and, in the real world, we need them even if they are a possible risk. Protecting your site depends on your business models and your sources of revenue.<br \/>\nRegarding Tracking code and advertising there are 3 main approaches:<br \/>\n<strong>1) avoid them<\/strong><br \/>\nIf you can avoid advertising and 3rd part tracking codes in your site, this for sure will make your life safer. Not only for the risk of malware code, but for the risk your page is not loaded correctly by the final users, or part of them, because the source of this advertising or tracking codes is not available, is performing under expectation, has any error, is not compatible with some browsers, and so on. This does not mean to remove these stuff from all the pages of your site, maybe from the critical pages (login, profile pages, payment pages,&#8230;)<br \/>\n<strong>2) isolate them<\/strong><br \/>\nIframe with sandbox is a good solution to isolate piece of code\/content and block any chance of bad code to look around your page. It does not work with all the code. Google analytics needs to be in your page, it does not work as supposed if located inside an iframes. The same for some advertising tag and tracking code. Multi location advertising (multiple advertising in the same page) need to be coordinated to avoid competitor advertising in the same page, and to be coordinate they need to see each other. These can&#8217;t be isolated with iframe sandbox. Take a look to this page about\u00a0<a href=\"https:\/\/msdn.microsoft.com\/it-it\/hh563496.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">HTML5 sandbox<\/a>. You can start implementing Content Security Policy as detailed described in this post about <a href=\"http:\/\/www.html5rocks.com\/en\/tutorials\/security\/content-security-policy\/\">Content Security Policy. <\/a><br \/>\nPay attention: Some malvertising are able to install viruses and trojan software in the client PC, just because they appeared in the webpage. If you are able to isolate the advertising in a sandbox, this can block the malicious script to interact with your page, not to install malware.<br \/>\n<strong>3) audit them<\/strong><br \/>\nThis is the most time consuming activity. Pay attention to any script\/include you put in your page. Take a look to the source of this code. Maybe there are sources you relay upon more than other. Allow external includes only when you are sure of the content and you are sure this external part is not including something else. Better if you download this 3rd part code, save it in your site and include it from your repository, just to be sure nobody will change it without your approval. But it must be always the same. Most of the times this approach is not compatible with tracking codes and advertising, because the script changes every call or the call itself is used to track the data, like getting the transparent pixel.<\/p>\n<p><strong>Content Security Policy<\/strong><br \/>\nRecent browsers implement CSP, Content Security Policy, so now you are able to define some rules to restrict the behavior of external content based. CSP provides a method for website developers to define approved origins of content that browsers should be allowed to load on that website page. This policy is applied to content types like JavaScript, CSS, HTML frames, web workers, fonts, images, embeddable objects such as Java applets, ActiveX, audio and video files, and other HTML5 features.<br \/>\nAs often happened in the past, there is not shared a standard. Content security Policy are implemented in different browser with different mechanisms.<\/p>\n<table>\n<tbody>\n<tr>\n<td>Response Header<\/td>\n<td>IExplorer<\/td>\n<td>Firefox<\/td>\n<td>Chrome<\/td>\n<td>Safari<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>Content-Security-Policy<\/pre>\n<\/td>\n<td>no<\/td>\n<td>from v.40<\/td>\n<td>from v.43<\/td>\n<td>from v.8<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>X-Content-Security-Policy - deprecated<\/pre>\n<\/td>\n<td>from v.10 partial<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>X-Webkit-CSP - deprecated<\/pre>\n<\/td>\n<td>no<\/td>\n<td>from v.4 to v.22<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td colspan=\"5\">details from: <a href=\"http:\/\/caniuse.com\/#search=ContentSecurityPolicy\">caniuse.com\/ContentSecurityPolicy<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Content-Security-Policy should be the official standard response header to implement CSP, even if at this moment it is not supported by Microsoft Internet Explorer.<\/p>\n<p><strong>Final thoughts<\/strong><br \/>\nSecurity does not come for free. Protect your critical pages, like registration, payment, login, removing any advertising or tracking codes. Use only the ones from reliable sources with a defined content.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Your pages and your site are exposed to became the container of malicious code, code somebody placed in your page without your approval. You include code from outside, because you need advertising and tracking codes, but these elements are out of your control. Malvertising and bad tracking codes are ready to take control of your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[12],"tags":[26,40,27,29,28,25,24],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-web","tag-advertising","tag-content-security-policy","tag-iframe","tag-javascript","tag-sandbox","tag-tag","tag-tracking","no-thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Protect your site from malvertising and bad tracking codes - I Love Secure<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Protect your site from malvertising and bad tracking codes - I Love Secure\" \/>\n<meta property=\"og:description\" content=\"Your pages and your site are exposed to became the container of malicious code, code somebody placed in your page without your approval. You include code from outside, because you need advertising and tracking codes, but these elements are out of your control. Malvertising and bad tracking codes are ready to take control of your [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/\" \/>\n<meta property=\"og:site_name\" content=\"I Love Secure\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-22T23:01:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-07-21T21:43:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising-1024x417.png\" \/>\n<meta name=\"author\" content=\"secureadm\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"secureadm\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/\",\"url\":\"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/\",\"name\":\"Protect your site from malvertising and bad tracking codes - I Love Secure\",\"isPartOf\":{\"@id\":\"https:\/\/www.ilovesecure.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising-1024x417.png\",\"datePublished\":\"2015-11-22T23:01:44+00:00\",\"dateModified\":\"2020-07-21T21:43:05+00:00\",\"author\":{\"@id\":\"https:\/\/www.ilovesecure.com\/#\/schema\/person\/4f0f645b7843e70f478415155f2b0b07\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/#primaryimage\",\"url\":\"https:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising.png\",\"contentUrl\":\"https:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising.png\",\"width\":1234,\"height\":503},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.ilovesecure.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Protect your site from malvertising and bad tracking codes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.ilovesecure.com\/#website\",\"url\":\"https:\/\/www.ilovesecure.com\/\",\"name\":\"I Love Secure\",\"description\":\"Security step by step\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.ilovesecure.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.ilovesecure.com\/#\/schema\/person\/4f0f645b7843e70f478415155f2b0b07\",\"name\":\"secureadm\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.ilovesecure.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7ae680ceca3544c8a37149e6254db758ee7c1ecefd5c6ad34aa972b9c5bfd1d0?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7ae680ceca3544c8a37149e6254db758ee7c1ecefd5c6ad34aa972b9c5bfd1d0?s=96&d=mm&r=g\",\"caption\":\"secureadm\"},\"url\":\"https:\/\/www.ilovesecure.com\/index.php\/author\/secureadm\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Protect your site from malvertising and bad tracking codes - I Love Secure","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/","og_locale":"en_US","og_type":"article","og_title":"Protect your site from malvertising and bad tracking codes - I Love Secure","og_description":"Your pages and your site are exposed to became the container of malicious code, code somebody placed in your page without your approval. You include code from outside, because you need advertising and tracking codes, but these elements are out of your control. Malvertising and bad tracking codes are ready to take control of your [&hellip;]","og_url":"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/","og_site_name":"I Love Secure","article_published_time":"2015-11-22T23:01:44+00:00","article_modified_time":"2020-07-21T21:43:05+00:00","og_image":[{"url":"https:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising-1024x417.png","type":"","width":"","height":""}],"author":"secureadm","twitter_card":"summary_large_image","twitter_misc":{"Written by":"secureadm","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/","url":"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/","name":"Protect your site from malvertising and bad tracking codes - I Love Secure","isPartOf":{"@id":"https:\/\/www.ilovesecure.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/#primaryimage"},"image":{"@id":"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/#primaryimage"},"thumbnailUrl":"https:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising-1024x417.png","datePublished":"2015-11-22T23:01:44+00:00","dateModified":"2020-07-21T21:43:05+00:00","author":{"@id":"https:\/\/www.ilovesecure.com\/#\/schema\/person\/4f0f645b7843e70f478415155f2b0b07"},"breadcrumb":{"@id":"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/#primaryimage","url":"https:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising.png","contentUrl":"https:\/\/www.ilovesecure.com\/wp-content\/uploads\/2015\/11\/malvertising.png","width":1234,"height":503},{"@type":"BreadcrumbList","@id":"https:\/\/www.ilovesecure.com\/index.php\/2015\/11\/22\/protect-your-site-from-malvertising-tracking-code-iframes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.ilovesecure.com\/"},{"@type":"ListItem","position":2,"name":"Protect your site from malvertising and bad tracking codes"}]},{"@type":"WebSite","@id":"https:\/\/www.ilovesecure.com\/#website","url":"https:\/\/www.ilovesecure.com\/","name":"I Love Secure","description":"Security step by step","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.ilovesecure.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.ilovesecure.com\/#\/schema\/person\/4f0f645b7843e70f478415155f2b0b07","name":"secureadm","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.ilovesecure.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7ae680ceca3544c8a37149e6254db758ee7c1ecefd5c6ad34aa972b9c5bfd1d0?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7ae680ceca3544c8a37149e6254db758ee7c1ecefd5c6ad34aa972b9c5bfd1d0?s=96&d=mm&r=g","caption":"secureadm"},"url":"https:\/\/www.ilovesecure.com\/index.php\/author\/secureadm\/"}]}},"_links":{"self":[{"href":"https:\/\/www.ilovesecure.com\/index.php\/wp-json\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ilovesecure.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ilovesecure.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ilovesecure.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ilovesecure.com\/index.php\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":22,"href":"https:\/\/www.ilovesecure.com\/index.php\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":197,"href":"https:\/\/www.ilovesecure.com\/index.php\/wp-json\/wp\/v2\/posts\/109\/revisions\/197"}],"wp:attachment":[{"href":"https:\/\/www.ilovesecure.com\/index.php\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ilovesecure.com\/index.php\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ilovesecure.com\/index.php\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}