mirror of
				https://github.com/sinatra/sinatra
				synced 2023-03-27 23:18:01 -04:00 
			
		
		
		
	Fix content security policy no-arg directives
Many of the CSP3 no-arg directives are multiple words so calling `sub` only transforms the first "_" to a "-" when we need to transform all of them to have a valid directive.
This commit is contained in:
		
							parent
							
								
									a4dd24add2
								
							
						
					
					
						commit
						5548212f47
					
				
					 2 changed files with 2 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -62,7 +62,7 @@ module Rack
 | 
			
		|||
        # Set these key values to boolean 'true' to include in policy
 | 
			
		||||
        NO_ARG_DIRECTIVES.each do |d|
 | 
			
		||||
          if options.key?(d) && options[d].is_a?(TrueClass)
 | 
			
		||||
            directives << d.to_s.sub(/_/, '-')
 | 
			
		||||
            directives << d.to_s.gsub(/_/, '-')
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,7 +33,7 @@ describe Rack::Protection::ContentSecurityPolicy do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    headers = get('/', {}, 'wants' => 'text/html').headers
 | 
			
		||||
    expect(headers["Content-Security-Policy"]).to eq("block-all_mixed_content; connect-src 'self'; default-src none; disown-opener; img-src 'self'; script-src 'self'; style-src 'self'; upgrade-insecure_requests")
 | 
			
		||||
    expect(headers["Content-Security-Policy"]).to eq("block-all-mixed-content; connect-src 'self'; default-src none; disown-opener; img-src 'self'; script-src 'self'; style-src 'self'; upgrade-insecure-requests")
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it 'should ignore CSP3 no arg directives unless they are set to true' do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue