devfortress-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +7 -0
- data/LICENSE +63 -0
- data/README.md +121 -0
- data/Rakefile +11 -0
- data/lib/devfortress/agent_adapter.rb +185 -0
- data/lib/devfortress/agent_loop_detector.rb +167 -0
- data/lib/devfortress/agent_output_exfiltration_detector.rb +115 -0
- data/lib/devfortress/agent_security.rb +431 -0
- data/lib/devfortress/alias_verify.rb +87 -0
- data/lib/devfortress/api_key_aliasing.rb +240 -0
- data/lib/devfortress/bounded_map.rb +80 -0
- data/lib/devfortress/circuit_breaker.rb +149 -0
- data/lib/devfortress/classifier.rb +133 -0
- data/lib/devfortress/client.rb +380 -0
- data/lib/devfortress/client_ip.rb +28 -0
- data/lib/devfortress/clock_drift_detector.rb +71 -0
- data/lib/devfortress/credential_isolation.rb +340 -0
- data/lib/devfortress/credential_vault.rb +93 -0
- data/lib/devfortress/delivery_result.rb +9 -0
- data/lib/devfortress/graduated_rate_limiter.rb +270 -0
- data/lib/devfortress/internal_closed_loop_engine.rb +658 -0
- data/lib/devfortress/license_manager.rb +297 -0
- data/lib/devfortress/observer.rb +62 -0
- data/lib/devfortress/prompt_injection_filter.rb +73 -0
- data/lib/devfortress/response_webhook_client.rb +165 -0
- data/lib/devfortress/shadow_agent_registry.rb +123 -0
- data/lib/devfortress/signer.rb +134 -0
- data/lib/devfortress/telemetry.rb +407 -0
- data/lib/devfortress/tier_gate.rb +294 -0
- data/lib/devfortress/tool_call_sequence_validator.rb +126 -0
- data/lib/devfortress/transport.rb +31 -0
- data/lib/devfortress/unified_audit_trail.rb +213 -0
- data/lib/devfortress/version.rb +5 -0
- data/lib/devfortress/webhook_verification.rb +9 -0
- data/lib/devfortress/webhook_verifier.rb +93 -0
- data/lib/devfortress.rb +96 -0
- metadata +110 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "openssl"
|
|
5
|
+
require "time"
|
|
6
|
+
|
|
7
|
+
require_relative "webhook_verification"
|
|
8
|
+
|
|
9
|
+
module DevFortress
|
|
10
|
+
# Inbound webhook signature verification.
|
|
11
|
+
#
|
|
12
|
+
# Contract (platform dispatcher, POST /api/webhooks/deliver):
|
|
13
|
+
#
|
|
14
|
+
# - X-DevFortress-Timestamp: ISO-8601 UTC timestamp of dispatch.
|
|
15
|
+
# - X-DevFortress-Signature: hex HMAC-SHA256, keyed with the project's
|
|
16
|
+
# webhook secret, over the UTF-8 bytes of "{timestamp}.{rawBody}".
|
|
17
|
+
# - Timestamps older than 300 seconds are rejected.
|
|
18
|
+
# - The body carries a 32-char lowercase-hex "nonce". Replay tracking is left
|
|
19
|
+
# to the caller through +nonce_check+ so the library keeps no state.
|
|
20
|
+
module WebhookVerifier
|
|
21
|
+
TOLERANCE_SECONDS = 300
|
|
22
|
+
SIGNATURE_HEADER = "X-DevFortress-Signature"
|
|
23
|
+
TIMESTAMP_HEADER = "X-DevFortress-Timestamp"
|
|
24
|
+
|
|
25
|
+
HEX_SIGNATURE = /\A[0-9a-fA-F]{64}\z/.freeze
|
|
26
|
+
HEX_NONCE = /\A[0-9a-f]{32}\z/.freeze
|
|
27
|
+
|
|
28
|
+
# Verify a DevFortress webhook. Pass the body exactly as received.
|
|
29
|
+
#
|
|
30
|
+
# +nonce_check+ should return true the first time a nonce is seen and
|
|
31
|
+
# false on replay; when supplied, a missing or malformed nonce fails.
|
|
32
|
+
# +now+ is for tests: a Time, or an ISO-8601 string.
|
|
33
|
+
def self.verify(raw_body:, signature:, timestamp:, secret:, tolerance_seconds: TOLERANCE_SECONDS, now: nil, nonce_check: nil)
|
|
34
|
+
ts_ms = parse_iso_ms(timestamp)
|
|
35
|
+
return WebhookVerification.new(false, "invalid_timestamp") if ts_ms.nil?
|
|
36
|
+
|
|
37
|
+
age_ms = now_ms(now) - ts_ms
|
|
38
|
+
return WebhookVerification.new(false, "timestamp_expired") if age_ms > tolerance_seconds * 1000
|
|
39
|
+
|
|
40
|
+
return WebhookVerification.new(false, "invalid_signature") unless HEX_SIGNATURE.match?(signature)
|
|
41
|
+
|
|
42
|
+
expected = OpenSSL::HMAC.digest("SHA256", secret, "#{timestamp}.#{raw_body}")
|
|
43
|
+
given = [signature].pack("H*")
|
|
44
|
+
return WebhookVerification.new(false, "signature_mismatch") unless secure_compare(expected, given)
|
|
45
|
+
|
|
46
|
+
if nonce_check
|
|
47
|
+
decoded = begin
|
|
48
|
+
JSON.parse(raw_body)
|
|
49
|
+
rescue JSON::ParserError
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
52
|
+
return WebhookVerification.new(false, "invalid_body") unless decoded.is_a?(Hash)
|
|
53
|
+
|
|
54
|
+
nonce = decoded["nonce"]
|
|
55
|
+
return WebhookVerification.new(false, "nonce_invalid") unless nonce.is_a?(String) && HEX_NONCE.match?(nonce)
|
|
56
|
+
return WebhookVerification.new(false, "replay_detected") unless nonce_check.call(nonce)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
WebhookVerification.new(true, nil)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Epoch milliseconds for a strict ISO-8601 timestamp with a zone, or nil
|
|
63
|
+
# when malformed or not a real calendar date/time.
|
|
64
|
+
def self.parse_iso_ms(value)
|
|
65
|
+
t = Time.iso8601(value)
|
|
66
|
+
(t.to_r * 1000).to_i
|
|
67
|
+
rescue ArgumentError
|
|
68
|
+
nil
|
|
69
|
+
end
|
|
70
|
+
private_class_method :parse_iso_ms
|
|
71
|
+
|
|
72
|
+
def self.now_ms(now)
|
|
73
|
+
case now
|
|
74
|
+
when nil
|
|
75
|
+
(Time.now.to_r * 1000).to_i
|
|
76
|
+
when Time
|
|
77
|
+
(now.to_r * 1000).to_i
|
|
78
|
+
when String
|
|
79
|
+
parse_iso_ms(now) or raise ArgumentError, "now must be an ISO-8601 timestamp"
|
|
80
|
+
else
|
|
81
|
+
(now.to_r * 1000).to_i
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
private_class_method :now_ms
|
|
85
|
+
|
|
86
|
+
def self.secure_compare(a, b)
|
|
87
|
+
return false unless a.bytesize == b.bytesize
|
|
88
|
+
|
|
89
|
+
OpenSSL.fixed_length_secure_compare(a, b)
|
|
90
|
+
end
|
|
91
|
+
private_class_method :secure_compare
|
|
92
|
+
end
|
|
93
|
+
end
|
data/lib/devfortress.rb
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "devfortress/version"
|
|
4
|
+
require_relative "devfortress/signer"
|
|
5
|
+
require_relative "devfortress/client_ip"
|
|
6
|
+
require_relative "devfortress/classifier"
|
|
7
|
+
require_relative "devfortress/delivery_result"
|
|
8
|
+
require_relative "devfortress/transport"
|
|
9
|
+
require_relative "devfortress/client"
|
|
10
|
+
require_relative "devfortress/webhook_verification"
|
|
11
|
+
require_relative "devfortress/webhook_verifier"
|
|
12
|
+
require_relative "devfortress/observer"
|
|
13
|
+
|
|
14
|
+
# Tier 2 (public pillars only — see lib/devfortress/internal.rb, not
|
|
15
|
+
# required here, for the gated surface).
|
|
16
|
+
require_relative "devfortress/credential_vault"
|
|
17
|
+
require_relative "devfortress/credential_isolation"
|
|
18
|
+
require_relative "devfortress/agent_adapter"
|
|
19
|
+
require_relative "devfortress/agent_security"
|
|
20
|
+
require_relative "devfortress/api_key_aliasing"
|
|
21
|
+
require_relative "devfortress/alias_verify"
|
|
22
|
+
require_relative "devfortress/tool_call_sequence_validator"
|
|
23
|
+
require_relative "devfortress/agent_loop_detector"
|
|
24
|
+
require_relative "devfortress/prompt_injection_filter"
|
|
25
|
+
require_relative "devfortress/response_webhook_client"
|
|
26
|
+
|
|
27
|
+
# Filing 4 (B7/B10) — public, disclosure-comment only (see PATENT-GATE
|
|
28
|
+
# comments in each file), matching the Node SDK's posture. B3/B4 are
|
|
29
|
+
# gated as of TODO 420 (2026-11-03) — see lib/devfortress/internal.rb.
|
|
30
|
+
require_relative "devfortress/agent_output_exfiltration_detector"
|
|
31
|
+
require_relative "devfortress/shadow_agent_registry"
|
|
32
|
+
|
|
33
|
+
# License/telemetry/tier-gating (CV-M1/M2/M4/M7, CV-S2-S6) — client-side
|
|
34
|
+
# port of the platform license-check/heartbeat fix (TODO 321) and the
|
|
35
|
+
# Node SDK's tier enforcement. Mirrors license-manager.ts, telemetry.ts,
|
|
36
|
+
# telemetry-rollup-buffer.ts and tier-gate.ts.
|
|
37
|
+
require_relative "devfortress/license_manager"
|
|
38
|
+
require_relative "devfortress/telemetry"
|
|
39
|
+
require_relative "devfortress/tier_gate"
|
|
40
|
+
|
|
41
|
+
# Graduated rate limiting (Invention A3, TODO 373) + platform circuit
|
|
42
|
+
# breaking / bounded map (TODO 372). Mirrors graduated-rate-limiter.ts,
|
|
43
|
+
# circuit-breaker.ts, and internal-closed-loop-engine.ts's BoundedMap.
|
|
44
|
+
require_relative "devfortress/graduated_rate_limiter"
|
|
45
|
+
require_relative "devfortress/circuit_breaker"
|
|
46
|
+
require_relative "devfortress/bounded_map"
|
|
47
|
+
|
|
48
|
+
# Internal Closed-Loop Protection Engine (TODO 407 port) — internal/hybrid
|
|
49
|
+
# CL mode's 3-tier decision engine. Mirrors internal-closed-loop-engine.ts.
|
|
50
|
+
require_relative "devfortress/internal_closed_loop_engine"
|
|
51
|
+
|
|
52
|
+
# Cold-start behavioral baselines (Invention A1, TODO 374) + LSH
|
|
53
|
+
# fingerprint clustering / campaign detection (Invention A2, TODO 374).
|
|
54
|
+
# Mirrors cold-start-detector.ts and lsh-cluster-engine.ts.
|
|
55
|
+
#
|
|
56
|
+
# Conditional (2026-11-08 standalone-build audit, round 2, Part 3): neither
|
|
57
|
+
# class is referenced anywhere else in this gem (confirmed — grepped client.rb/
|
|
58
|
+
# observer.rb/every other lib file before making this conditional), so unlike
|
|
59
|
+
# the Node SDK's cold-start-detector.ts/lsh-cluster-engine.ts (hard-wired into
|
|
60
|
+
# DevFortressCore's own observe() path, requiring a behavioral stub — see
|
|
61
|
+
# open-core-strip.sh Op 14), a bare require boundary is sufficient here: on
|
|
62
|
+
# the open-core checkout these two files are proprietary and stripped, and
|
|
63
|
+
# DevFortress::ColdStartDetector / DevFortress::LSHClusterEngine simply don't
|
|
64
|
+
# exist — no other code path depends on them existing. In the private repo
|
|
65
|
+
# both files are always present, so this rescue branch never fires there.
|
|
66
|
+
begin
|
|
67
|
+
require_relative "devfortress/cold_start_detector"
|
|
68
|
+
require_relative "devfortress/lsh_cluster_engine"
|
|
69
|
+
rescue LoadError
|
|
70
|
+
nil
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Clock drift anomaly detection (Invention A18, TODO 419/422).
|
|
74
|
+
# Mirrors security-extensions.ts's ClockDriftDetector.
|
|
75
|
+
require_relative "devfortress/clock_drift_detector"
|
|
76
|
+
|
|
77
|
+
# Unified audit trail (CL-M3, TODO 371) -- in-memory only, not
|
|
78
|
+
# tamper-evident; see unified_audit_trail.rb's own comment. AbuseIPDB
|
|
79
|
+
# threat-intel enrichment (TODO 375). Mirrors unified-audit.ts and
|
|
80
|
+
# abuseipdb.ts.
|
|
81
|
+
require_relative "devfortress/unified_audit_trail"
|
|
82
|
+
# Conditional (2026-11-08 standalone-build audit, round 2, Part 3): the
|
|
83
|
+
# AbuseIPDB trade-secret integration is proprietary and stripped from the
|
|
84
|
+
# open-core checkout. Not referenced anywhere else in this gem (same check
|
|
85
|
+
# as cold_start_detector/lsh_cluster_engine above), so a bare require
|
|
86
|
+
# boundary is sufficient — DevFortress::AbuseIPDB simply doesn't exist on
|
|
87
|
+
# that checkout. Never fires in the private repo, where the file always
|
|
88
|
+
# exists.
|
|
89
|
+
begin
|
|
90
|
+
require_relative "devfortress/abuseipdb"
|
|
91
|
+
rescue LoadError
|
|
92
|
+
nil
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
module DevFortress
|
|
96
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: devfortress-sdk
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Duncan Ndungu Ndegwa
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-11-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: minitest
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '5.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: webrick
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.8'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.8'
|
|
41
|
+
description: 'Event reporting client for DevFortress (external mode): request signing,
|
|
42
|
+
classification and webhook verification for Ruby applications (Rails, Rack, Sinatra).
|
|
43
|
+
Pre-release, not published.'
|
|
44
|
+
email:
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- ".gitignore"
|
|
50
|
+
- Gemfile
|
|
51
|
+
- LICENSE
|
|
52
|
+
- README.md
|
|
53
|
+
- Rakefile
|
|
54
|
+
- lib/devfortress.rb
|
|
55
|
+
- lib/devfortress/agent_adapter.rb
|
|
56
|
+
- lib/devfortress/agent_loop_detector.rb
|
|
57
|
+
- lib/devfortress/agent_output_exfiltration_detector.rb
|
|
58
|
+
- lib/devfortress/agent_security.rb
|
|
59
|
+
- lib/devfortress/alias_verify.rb
|
|
60
|
+
- lib/devfortress/api_key_aliasing.rb
|
|
61
|
+
- lib/devfortress/bounded_map.rb
|
|
62
|
+
- lib/devfortress/circuit_breaker.rb
|
|
63
|
+
- lib/devfortress/classifier.rb
|
|
64
|
+
- lib/devfortress/client.rb
|
|
65
|
+
- lib/devfortress/client_ip.rb
|
|
66
|
+
- lib/devfortress/clock_drift_detector.rb
|
|
67
|
+
- lib/devfortress/credential_isolation.rb
|
|
68
|
+
- lib/devfortress/credential_vault.rb
|
|
69
|
+
- lib/devfortress/delivery_result.rb
|
|
70
|
+
- lib/devfortress/graduated_rate_limiter.rb
|
|
71
|
+
- lib/devfortress/internal_closed_loop_engine.rb
|
|
72
|
+
- lib/devfortress/license_manager.rb
|
|
73
|
+
- lib/devfortress/observer.rb
|
|
74
|
+
- lib/devfortress/prompt_injection_filter.rb
|
|
75
|
+
- lib/devfortress/response_webhook_client.rb
|
|
76
|
+
- lib/devfortress/shadow_agent_registry.rb
|
|
77
|
+
- lib/devfortress/signer.rb
|
|
78
|
+
- lib/devfortress/telemetry.rb
|
|
79
|
+
- lib/devfortress/tier_gate.rb
|
|
80
|
+
- lib/devfortress/tool_call_sequence_validator.rb
|
|
81
|
+
- lib/devfortress/transport.rb
|
|
82
|
+
- lib/devfortress/unified_audit_trail.rb
|
|
83
|
+
- lib/devfortress/version.rb
|
|
84
|
+
- lib/devfortress/webhook_verification.rb
|
|
85
|
+
- lib/devfortress/webhook_verifier.rb
|
|
86
|
+
homepage: https://github.com/duncan982/devfortress-core/tree/main/packages/devfortress-ruby
|
|
87
|
+
licenses:
|
|
88
|
+
- BUSL-1.1
|
|
89
|
+
metadata:
|
|
90
|
+
homepage_uri: https://github.com/duncan982/devfortress-core/tree/main/packages/devfortress-ruby
|
|
91
|
+
post_install_message:
|
|
92
|
+
rdoc_options: []
|
|
93
|
+
require_paths:
|
|
94
|
+
- lib
|
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
|
+
requirements:
|
|
97
|
+
- - ">="
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: '3.0'
|
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ">="
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '0'
|
|
105
|
+
requirements: []
|
|
106
|
+
rubygems_version: 3.4.20
|
|
107
|
+
signing_key:
|
|
108
|
+
specification_version: 4
|
|
109
|
+
summary: DevFortress Security SDK
|
|
110
|
+
test_files: []
|