1

我目前正在努力学习更多关于nginx和给定的安全性作为网络服务器。我的虚拟设置是带有3个虚拟主机的nginx。这些主机中的每一个都运行着一个博客。如何找出nginx(虚拟主机)的合理内容安全策略来源?

在研究了一些针对nginx的强化教程之后,我确实发现自己停留在那些http-headers ......我不确定通过nginx实施内容安全策略是否正确,如果我有多个虚拟主机,来自不同网站的不同内容。

但是我现在的位置是想知道如何为每个*-src参数中的nginx设置一个合理的内容安全策略白名单。

directive reference and source list reference也没有 the latest content security policy level 3没有回答所有*-src“最佳实践白名单”的问题。

比方说,我已经把'self'每这些参数:

  • default-src

这是如果设置为'self'

    这将是有意义的唯一参数
  • script-src,style-src,img-srcconnect-srcfont-srcchild-src

剩下的就是给我一个真正的头痛。我该如何知道每一个好消息?如果我将这些设置为'self',用户总是会得到一个400 HTTP错误?

就像我之前说过的,我不确定通过nginx实施内容安全策略是否正确。如果我以5+客户端运行网络服务器,那么我不可能知道这些客户端的每个“好”来源。我想再次指出,我只是想知道这些源参数。其他的HTTP头(不仅仅是内容安全策略)对我来说是合理的,而且是完全合理的。

问候, Megajin

回答

6

我去了,把我的问题的一些更多的研究。目前,我对我的配置很满意,我将在本文的底部分享这些配置。

这个#1的问题实际上是一个很好的起点:How does Content Security Policy work?

我最后的立足点是争取一切,如果任何用户是得到一个CSP - 错误,他们必须告诉他们希望服务器管理员添加另一个来源到CSP。如果源似乎值得信赖,它将被添加,否则被拒绝(我可能以某种方式自动执行该过程)。

如果有人有兴趣进一步SSL配置你可以看一下这个github上页:https://gist.github.com/plentz/6737338

这里是我的nginx的头配置:

# don't send the nginx version number in error pages and Server header 
    server_tokens off; 

# config to don't allow the browser to render the page inside an frame or iframe 
# and avoid clickjacking http://en.wikipedia.org/wiki/Clickjacking 
# if you need to allow [i]frames, you can use SAMEORIGIN or even set an uri with ALLOW-FROM uri 
# https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options 
add_header X-Frame-Options SAMEORIGIN always; 

# when serving user-supplied content, include a X-Content-Type-Options: nosniff header along with the Content-Type: header, 
# to disable content-type sniffing on some browsers. 
# https://www.owasp.org/index.php/List_of_useful_HTTP_headers 
# currently suppoorted in IE > 8 http://blogs.msdn.com/b/ie/archive/2008/09/02/ie8-security-part-vi-beta-2-update.aspx 
# http://msdn.microsoft.com/en-us/library/ie/gg622941(v=vs.85).aspx 
# 'soon' on Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=471020 
add_header X-Content-Type-Options nosniff always; 

# This header enables the Cross-site scripting (XSS) filter built into most recent web browsers. 
# It's usually enabled by default anyway, so the role of this header is to re-enable the filter for 
# this particular website if it was disabled by the user. 
# https://www.owasp.org/index.php/List_of_useful_HTTP_headers 
add_header X-XSS-Protection "1; mode=block" always; 

# with Content Security Policy (CSP) enabled(and a browser that supports it(http://caniuse.com/#feat=contentsecuritypolicy), 
# you can tell the browser that it can only download content from the domains you explicitly allow 
# http://www.html5rocks.com/en/tutorials/security/content-security-policy/ 
# https://www.owasp.org/index.php/Content_Security_Policy 
# I need to change our application code so we can increase security by disabling 'unsafe-inline' 'unsafe-eval' 
# directives for css and js(if you have inline css or js, you will need to keep it too). 
# more: http://www.html5rocks.com/en/tutorials/security/content-security-policy/#inline-code-considered-harmful 
add_header Content-Security-Policy "default-src 'self' https://google.com https://youtube.com https://facebook.com https://fonts.google.com https://fonts.googleapis.com https://ajax.googleapis.com https://www.google-analytics.com https://cdnjs.cloudflare.com https://code.jquery.com https://connect.facebook.net https://s.imgur.com https://imgur.com https://i.imgur.com https://500px.com https://drscdn.500px.org https://www.reddit.com https://www.flickr.com https://c1.staticflickr.com https://maxcdn.bootstrapcdn.com http://code.ionicframework.com https://cdn.fontawesome.com/; 
    script-src 'self' 'unsafe-inline'; 
    style-src 'self'; 
    img-src 'self' data:; 
    connect-src 'self'; 
    font-src 'self'; 
    object-src 'none'; 
    media-src 'self'; 
    form-action 'self'; 
    frame-ancestors 'self';" always; 

这将是的帮助下很长的学习过程我的用户。 我希望这会帮助别人。