CodeSampleX

サンプル

rack-test 2.2.0: Show that Rack::Test only honored secure cookies when the `Secure` attribute is parsed case-insensitively in 2.2.0.

検証済みサンプル — gem rack-test 2.2.0: Show that Rack::Test only honored secure cookies when the `Secure` attribute is parsed case-insensitively in 2.2.0. ruby 3 …

sha256:9e8d4bd2244417402cfedd6861a8b9f55887ef04d103e164aba7aa80f3fa49ac

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
1
宣言された環境 ruby linux x64 ruby ruby bundler

検証実行環境

環境 コントラクト ステージ 実行日
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

ケース

HOW
ゴール
Show that Rack::Test only honored secure cookies when the `Secure` attribute is parsed case-insensitively in 2.2.0.
パッケージ
シンボル
  • Rack::Test::Cookie
環境
ruby
作成日
2026-08-16T16:41:09Z

コントラクト

  1. A `Set-Cookie` header containing `Secure` in camel case is honored as a secure attribute, so the cookie is not sent on a plain HTTP follow-up request.
  2. When the same session makes an HTTPS request, that secure cookie is sent.
  3. The follow-up request body does not include `sid=ok` on HTTP but does include it when HTTPS is explicitly enabled.

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

Gemfile
source "https://rubygems.org"

gem "rack-test", "2.2.0"
NOTES.md
`search_known_solution` returned no rack-test hit for this query, so no existing sample was reused.

On 2.1.0 and earlier, `Set-Cookie: sid=ok; Secure` is treated like an unknown attribute case-wise, so the cookie leaks onto plain HTTP and the assertion that HTTPS-only behavior is enforced fails.
csx.json
{"case":{"believed":"A `Set-Cookie` flag named `Secure` is treated as case-sensitive in rack-test, so uppercase `Secure` behaves like an unknown token and is ignored.","caseId":"case:sha256:c6e68ff6fd227cb8159535678dbf70d74fe27aa3fbe0d6831340aafae4c793c4","contract":["A `Set-Cookie` header containing `Secure` in camel case is honored as a secure attribute, so the cookie is not sent on a plain HTTP follow-up request.","When the same session makes an HTTPS request, that secure cookie is sent.","The follow-up request body does not include `sid=ok` on HTTP but does include it when HTTPS is explicitly enabled."],"goal":"Show that Rack::Test only honored secure cookies when the `Secure` attribute is parsed case-insensitively in 2.2.0.","kind":"HOW","packages":["pkg:gem/rack-test@2.2.0"],"schemaVersion":1,"symbols":["Rack::Test::Cookie"]},"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-test@2.2.0"],"schemaVersion":1,"symbols":["Rack::Test::Cookie"],"verifierAdapter":"rubygems@1"}
test/contract.rb
require "rack/test"

class ContractApp
  include Rack::Test::Methods

  def app
    lambda do |env|
      case env["PATH_INFO"]
      when "/set"
        headers = {
          "content-type" => "text/plain",
          "set-cookie" => "sid=ok; Secure; Path=/"
        }
        [200, headers, ["set"]]
      when "/echo"
        [200, { "content-type" => "text/plain" }, [env["HTTP_COOKIE"].to_s]]
      else
        [404, { "content-type" => "text/plain" }, ["missing"]]
      end
    end
  end
end

def assert_true(condition, message)
  raise "CONTRACT FAIL: #{message}" unless condition
end

session = ContractApp.new

session.get("/set", {}, "HTTPS" => "on")
assert_true(session.last_response.body == "set", "initial HTTPS setup request should succeed")
assert_true(session.last_response['set-cookie']&.include?("sid=ok"), "secure cookie should be returned by the server")

session.get("/echo")
assert_true(session.last_response.body.empty?, "secure cookie with uppercase key should not be sent on HTTP")

session.get("/echo", {}, "HTTPS" => "on")
assert_true(session.last_response.body == "sid=ok", "secure cookie with uppercase key should be sent over HTTPS")

オリジンシーダー

csx-seed