Module: WebBotAuth::Signer
- Defined in:
- app/services/web_bot_auth/signer.rb
Overview
Produces the RFC 9421 request-signature headers for outbound bot/agent
requests.
Fail-open by design: any misconfiguration (no key, disabled, bad URL,
unexpected error) returns no headers and the caller proceeds unsigned —
signing must never break a fetch.
Constant Summary collapse
- VALIDITY =
The validity window for an outbound request signature.
5.minutes
Class Method Summary collapse
-
.headers_for(url:, now: Time.current) ⇒ Hash{String=>String}
Build the Web Bot Auth signing headers for a single outbound request.
Class Method Details
.headers_for(url:, now: Time.current) ⇒ Hash{String=>String}
Build the Web Bot Auth signing headers for a single outbound request.
The signature covers the target +@authority+ and our +signature-agent+,
so a receiving site can fetch our directory and verify the request.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/services/web_bot_auth/signer.rb', line 25 def headers_for(url:, now: Time.current) return {} unless WebBotAuth.sign_outbound? = WebBotAuth.(url) return {} if .blank? signature = WebBotAuth::MessageSignature.new( label: 'sig1', components: [ WebBotAuth::MessageSignature::Component.new(name: '@authority', value: ), WebBotAuth::MessageSignature::Component.new(name: 'signature-agent', value: WebBotAuth::SIGNATURE_AGENT) ], created: now.to_i, expires: (now + VALIDITY).to_i, keyid: WebBotAuth::Key.kid, tag: WebBotAuth::TAG_REQUEST ) { 'Signature-Agent' => WebBotAuth::SIGNATURE_AGENT }.merge(signature.headers) rescue StandardError => e Rails.logger.warn("[web_bot_auth] outbound signing skipped: #{e.class}: #{e.}") {} end |