{"id":3614,"date":"2023-07-06T16:28:01","date_gmt":"2023-07-06T22:28:01","guid":{"rendered":"https:\/\/www.mooreds.com\/wordpress\/?p=3614"},"modified":"2023-07-30T09:39:35","modified_gmt":"2023-07-30T15:39:35","slug":"protecting-a-cdn-source-using-basic-auth","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/3614","title":{"rendered":"Protecting a CDN source using basic auth"},"content":{"rendered":"<p>I have a website that is behind a content delivery network (CDN). I want to protect it from being crawled by any robots. I want all access to go through the CDN for reasons. There may be errant links to the source; I don&#8217;t care if they continue to work.<\/p>\n<p><code>htaccess<\/code> and basic auth is perfect for this situation.<\/p>\n<p>I added an <code>.htaccess<\/code> file that looks like this:<\/p>\n<pre><code>AuthType Basic\r\nAuthName \"Secure Content\"\r\nAuthUserFile \/path\/to\/.htpasswd\r\nrequire valid-user<\/code><\/pre>\n<p>I needed to make sure the path and the file are readable by the web server user.<\/p>\n<p>Then, I added a <code>.htpasswd<\/code> entry that looks like this:<\/p>\n<pre><code>user:passwdvalue<\/code><\/pre>\n<p>If you don&#8217;t have access to <code>htpasswd<\/code>, the typical program used to generate the password value, <a href=\"https:\/\/wtools.io\/generate-htpasswd-online\">this site will generate one for you<\/a>.<\/p>\n<p>Then, I had to configure my CDN to give it the appropriate header.<\/p>\n<p>Use the Authorization header, and make sure to pass the username and the password. <a href=\"https:\/\/www.blitter.se\/utils\/basic-authentication-header-generator\/\">This site will generate the appropriately base64 encoded values<\/a>.<\/p>\n<p>Voila. Only the CDN has access. <\/p>\n<p>Now, the flaws:<\/p>\n<ul>\n<li>Depending on how the CDN accesses the site, it may be possible to snoop out the username and password<\/li>\n<li>If you ever want to get the origin site over HTTP, you&#8217;ll need the username\/password<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I have a website that is behind a content delivery network (CDN). I want to protect it from being crawled by any robots. I want all access to go through [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,33],"tags":[],"class_list":["post-3614","post","type-post","status-publish","format-standard","hentry","category-tips","category-useful-tools"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/3614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=3614"}],"version-history":[{"count":1,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/3614\/revisions"}],"predecessor-version":[{"id":3615,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/3614\/revisions\/3615"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}