CodeSampleX

Exemplo

rack-protection 4.0.0: Detect silent middleware header name casing changes in rack-protection 4.x compared with 3.x.

Amostra verificada para gem rack-protection 4.0.0: Detect silent middleware header name casing changes in rack-protection 4.x compared with 3.x. O contrato…

sha256:54af8c0cb5ec887a12fc56af91226ed4576b60f9249d8282e6065d700f8465eb

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
2
Chaves de assinatura que o compilaram
1
Ambiente declarado ruby linux x64 ruby ruby bundler

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
ruby 3 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · rubygems@1
2026-08-16
ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · rubygems@1
2026-08-18

Caso

HOW
Objetivo
Detect silent middleware header name casing changes in rack-protection 4.x compared with 3.x.
Pacotes
Símbolos
  • Rack::Protection::XSSHeader
Ambiente
ruby
Criado
2026-08-16T16:39:07Z

Contrato

  1. `Rack::Protection::XSSHeader` with `nosniff: true` must emit `x-xss-protection` and `x-content-type-options` keys, not separate mixed-case variants.
  2. When `text/html` responses pass through XSSHeader, both lowercase keys must be present with values `1; mode=block` and `nosniff`.

Arquivos

  • Gemfile
  • NOTES.md
  • csx.json
  • test/contract.rb

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

Gemfile
source "https://rubygems.org"

gem "rack-protection", "4.0.0"
NOTES.md
A cache entry exists for a different sample in this library (`case:sha256:cb16ec9117c9887155c279e1e4607e740fe8c584754b3d6136855be6762490b`), so this sample targets a different trap: header-name casing in `Rack::Protection::XSSHeader`.

Using the wrong expectation (`X-XSS-Protection` / `X-Content-Type-Options`) fails only as a silent behavior mismatch: the app still returns a 200 and headers, but downstream middleware/tests that inspect only mixed-case names miss the protective header rewrite.
csx.json
{"case":{"believed":"Security middleware in Rack::Protection sets response security headers with mixed-case names like `X-XSS-Protection` and `X-Content-Type-Options`.","caseId":"case:sha256:515ed4c44ed5cf53ad43882dd1a4e36bbeb50ad8fd204390c7be70303c1584c9","contract":["`Rack::Protection::XSSHeader` with `nosniff: true` must emit `x-xss-protection` and `x-content-type-options` keys, not separate mixed-case variants.","When `text/html` responses pass through XSSHeader, both lowercase keys must be present with values `1; mode=block` and `nosniff`."],"goal":"Detect silent middleware header name casing changes in rack-protection 4.x compared with 3.x.","kind":"HOW","packages":["pkg:gem/rack-protection@4.0.0"],"schemaVersion":1,"symbols":["Rack::Protection::XSSHeader"]},"contractCommand":["ruby","test/contract.rb"],"environment":{"arch":"x64","ecosystem":"gem","executionContext":"ruby","language":"ruby","os":"linux","packageManager":"bundler","runtime":"ruby","schemaVersion":1},"license":"MIT-0","packages":["pkg:gem/rack-protection@4.0.0"],"schemaVersion":1,"symbols":["Rack::Protection::XSSHeader"],"verifierAdapter":"rubygems@1"}
test/contract.rb
# frozen_string_literal: true

require "stringio"
require "rack/protection/xss_header"

class HTMLApp
  def call(_env)
    [200, { "Content-Type" => "text/html" }, ["ok"]]
  end
end

app = Rack::Builder.new do
  use Rack::Protection::XSSHeader, nosniff: true, xss_mode: :block
  run HTMLApp.new
end.to_app

env = {
  "REQUEST_METHOD" => "GET",
  "SCRIPT_NAME" => "",
  "PATH_INFO" => "/",
  "QUERY_STRING" => "",
  "rack.url_scheme" => "http",
  "SERVER_NAME" => "example.org",
  "SERVER_PORT" => "80",
  "rack.input" => StringIO.new(""),
  "HTTPS" => "off"
}

status, headers, body = app.call(env)
body.close if body.respond_to?(:close)

unless status == 200
  warn "Expected HTTP 200, got #{status}"
  exit 1
end

unless headers["x-xss-protection"] == "1; mode=block"
  warn "Expected x-xss-protection to be set by XSSHeader"
  exit 1
end

unless headers["x-content-type-options"] == "nosniff"
  warn "Expected x-content-type-options to be set by XSSHeader"
  exit 1
end

if headers.key?("X-XSS-Protection") || headers.key?("X-Content-Type-Options")
  warn "Expected only lowercase security header keys in this Rack::Protection boundary"
  exit 1
end

puts "ok"

Seeder de origem

csx-seed