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; 

這將是的幫助下很長的學習過程我的用戶。 我希望這會幫助別人。