2014-11-05 1 views
1

가능한 한 엄격한 CSP (콘텐츠 보안 정책)를 구현하고 싶습니다. this intro on CSP에 따르면, 인라인 스타일 (강조 광산) 나쁜 :엄격한 Content-Security-Policy에 대해 레일즈가 인라인 CSS가없는 양식을 렌더링 할 수 있습니까?

인라인 스타일 같은 방식으로 처리됩니다 스타일 속성 및 스타일 태그 모두가 놀라 울 정도로 영리 다양한 데이터으로부터 보호하기 위해 외부 스타일 시트로 통합한다 CSS가 가능하게하는 exfiltration 메소드.

정말 인라인 스크립트와 스타일이 필요한 경우 script-src 또는 style-src 지시문에 'unsafe-inline'을 허용 된 소스로 추가하여 활성화 할 수 있습니다. 하지만 제발하지 마십시오.

기본 form_tag 방법은 (내가 실제로 토큰 인증을 찾고 있었다하지만 내 마크 업에서 찾을 수 없습니다) UTF-8 숨겨진 필드를 삽입 :

<div style="display:none"><input type="hidden" value="✓" name="utf8"></div> 

있는 - 때문에 display:none의 -

$ curl -I http://localhost:3000 | grep Content-Security | fold 
Content-Security-Policy-Report-Only: default-src https: 'self'; connect-src http 
s: 'self'; font-src https: data:; frame-src https: 'self'; img-src https: 'self' 
data:; media-src https: 'self'; object-src https: 'self'; script-src https: 'se 
lf'; style-src https: 'self'; 

내가 기본 방지하여 인라인 CSS의 내 CSP의 스타일하지만 레일을 허용하고 싶습니다 다음 CSP의 위반으로 파이어 폭스 (32)에보고됩니다 그. 내가 무엇을 할 수 있을지?

답변

0

레일과 함께 제공되는 extra_tags_for_html 메서드를 무시하고 인라인으로 추가하는 대신 div를 숨기는 클래스를 추가 할 수 있습니다.

def extra_tags_for_form(html_options) 
    authenticity_token = html_options.delete("authenticity_token") 
    method = html_options.delete("method").to_s 

    method_tag = case method 
    when /^get$/ # must be case-insensitive, but can't use downcase as might be nil 
     html_options["method"] = "get" 
     '' 
    when /^post$/, "", nil 
     html_options["method"] = "post" 
     token_tag(authenticity_token) 
    else 
     html_options["method"] = "post" 
     method_tag(method) + token_tag(authenticity_token) 
    end 

    tags = utf8_enforcer_tag << method_tag 
    #content_tag(:div, tags, :style => 'margin:0;padding:0;display:inline') 
    content_tag(:div, tags, :class => 'hidden_form_field') 
end 

원래 라인이 주석하고있다 : 이것은 당신이 찾고있는 같은 소리 것입니다 귀하의 사이트에있는 모든 형태에 영향을 미칠 것이라는 도우미이 추가 시도하지만 명심 당신이 그것을 대체 해야하는 라인은 아래와 같습니다. 또한 같은 시각 효과를 얻을 수있는 스타일이를 추가해야합니다 :

.hidden_form_field { 
    margin: 0; 
    padding: 0; 
    display: inline; 
} 

은 본질적으로, 당신은 그냥 랩 레일 방법을 무시하고 그 숨겨진 양식 필드 주위 DIV.

관련 문제