vybesec 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fff95dfb34e9210f86efa5190cfc428143f16d3cd095c36c33c5097de0c96665
4
+ data.tar.gz: f00015b5ce15530afe855d2175428eae1231a20b4b8991e95e0c545570a40b3b
5
+ SHA512:
6
+ metadata.gz: 2578c5bdb91988f4eb8091068b3ed5c767c4db752de0eb02281fd6ea17635ce0967e3cb5e7c68f3cef7e838ceb8952c0ccded1f26623d467b1714417a8552460
7
+ data.tar.gz: 1863db16b2547e54cf82709ed8dc2a3a830fd3a2f499d0ca5d5332e2298d4d5bbf2fd10f1fcfbffa39ae62a0cdcfc17192755ea7e0a04db08cecdecd694e9ae3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) VybeSec
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # vybesec (Ruby)
2
+
3
+ Ruby server SDK for VybeSec.
4
+
5
+ Gem name: `vybesec`
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ gem install vybesec
11
+ ```
12
+
13
+ or in your `Gemfile`:
14
+
15
+ ```ruby
16
+ gem "vybesec"
17
+ ```
18
+
19
+ ## Initialize
20
+
21
+ ```ruby
22
+ require "vybesec"
23
+
24
+ Vybesec.init(
25
+ key: "pk_live_YOUR_KEY",
26
+ platform: "other",
27
+ environment: "production",
28
+ release: "api@1.0.0"
29
+ )
30
+ ```
31
+
32
+ ## Manual capture
33
+
34
+ ```ruby
35
+ begin
36
+ process_checkout
37
+ rescue => e
38
+ Vybesec.capture_exception(
39
+ e,
40
+ route: "/api/checkout",
41
+ method: "POST",
42
+ status_code: 500,
43
+ request_body: '{"email":"person@example.com","token":"abc"}',
44
+ tags: { "component" => "payments" }
45
+ )
46
+ raise
47
+ end
48
+ ```
49
+
50
+ ## Rack middleware
51
+
52
+ ```ruby
53
+ # config.ru
54
+ require "vybesec"
55
+
56
+ Vybesec.init(key: ENV.fetch("VYBESEC_KEY"), platform: "other")
57
+
58
+ use Vybesec::Middleware
59
+ run MyRackApp
60
+ ```
61
+
62
+ The middleware captures thrown exceptions and re-raises them, and captures 5xx responses.
@@ -0,0 +1,183 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "securerandom"
4
+ require "uri"
5
+
6
+ require_relative "version"
7
+ require_relative "scrubber"
8
+
9
+ module Vybesec
10
+ Config = Struct.new(
11
+ :key,
12
+ :platform,
13
+ :runtime,
14
+ :server_platform,
15
+ :environment,
16
+ :release,
17
+ :ingest_url,
18
+ :timeout,
19
+ :debug,
20
+ :ignore_errors,
21
+ keyword_init: true
22
+ )
23
+
24
+ DEFAULT_INGEST_URL = "https://ingest.vybesec.com".freeze
25
+
26
+ class << self
27
+ attr_writer :transport
28
+
29
+ def init(key:, platform: "other", runtime: "ruby", server_platform: nil, environment: nil, release: "", ingest_url: DEFAULT_INGEST_URL, timeout: 2, debug: false, ignore_errors: [])
30
+ @config = Config.new(
31
+ key: key,
32
+ platform: platform.to_s.empty? ? "other" : platform,
33
+ runtime: runtime.to_s.empty? ? "ruby" : runtime,
34
+ server_platform: server_platform || detect_server_platform,
35
+ environment: environment || detect_environment,
36
+ release: release,
37
+ ingest_url: ingest_url.to_s.sub(%r{/$}, ""),
38
+ timeout: timeout,
39
+ debug: debug,
40
+ ignore_errors: Array(ignore_errors)
41
+ )
42
+ self
43
+ end
44
+
45
+ def capture_exception(exception, route: nil, method: nil, status_code: nil, request_body: nil, tags: {})
46
+ return unless configured?
47
+
48
+ message = Scrubber.scrub(exception.to_s)
49
+ return if ignored_error?(message)
50
+
51
+ payload = build_payload(
52
+ exception,
53
+ route: route,
54
+ method: method,
55
+ status_code: status_code,
56
+ request_body: request_body,
57
+ tags: tags
58
+ )
59
+
60
+ dispatch_payload(payload)
61
+ nil
62
+ rescue StandardError => e
63
+ debug_log("[VybeSec] capture failed: #{e.class}: #{e.message}")
64
+ nil
65
+ end
66
+
67
+ def scrub_sensitive_data(value)
68
+ Scrubber.scrub(value.to_s)
69
+ end
70
+
71
+ def reset!
72
+ @config = nil
73
+ @transport = nil
74
+ end
75
+
76
+ private
77
+
78
+ def dispatch_payload(payload)
79
+ if @transport
80
+ @transport.call(payload)
81
+ return
82
+ end
83
+
84
+ Thread.new { send_payload(payload) }
85
+ rescue StandardError => e
86
+ debug_log("[VybeSec] dispatch failed: #{e.class}: #{e.message}")
87
+ end
88
+
89
+ def send_payload(payload)
90
+ return unless configured?
91
+
92
+ uri = URI.parse("#{config.ingest_url}/v1/server-events/#{config.key}")
93
+ request = Net::HTTP::Post.new(uri.request_uri)
94
+ request["Content-Type"] = "application/json"
95
+ request.body = JSON.generate([payload])
96
+
97
+ Net::HTTP.start(
98
+ uri.host,
99
+ uri.port,
100
+ use_ssl: uri.scheme == "https",
101
+ open_timeout: config.timeout,
102
+ read_timeout: config.timeout,
103
+ ) do |http|
104
+ http.request(request)
105
+ end
106
+ rescue StandardError => e
107
+ debug_log("[VybeSec] send failed: #{e.class}: #{e.message}")
108
+ end
109
+
110
+ def build_payload(exception, route:, method:, status_code:, request_body:, tags:)
111
+ {
112
+ type: "error",
113
+ message: Scrubber.scrub(exception.to_s),
114
+ stackTrace: Scrubber.scrub(backtrace_for(exception)),
115
+ errorType: exception.class.name,
116
+ source: "server",
117
+ serverRuntime: config.runtime,
118
+ serverPlatform: config.server_platform,
119
+ serverRoute: route,
120
+ serverMethod: method,
121
+ serverStatusCode: status_code,
122
+ requestBody: scrub_and_truncate(request_body),
123
+ platform: config.platform,
124
+ environment: config.environment,
125
+ release: config.release,
126
+ sdkVersion: VERSION,
127
+ timestamp: (Time.now.to_f * 1000).to_i,
128
+ tags: tags || {},
129
+ sessionId: SecureRandom.hex(8),
130
+ }.compact
131
+ end
132
+
133
+ def backtrace_for(exception)
134
+ traces = Array(exception.backtrace)
135
+ return "" if traces.empty?
136
+
137
+ traces.join("\n")
138
+ end
139
+
140
+ def scrub_and_truncate(body)
141
+ return nil if body.nil? || body.to_s.empty?
142
+
143
+ Scrubber.scrub(body.to_s).slice(0, 500)
144
+ end
145
+
146
+ def ignored_error?(message)
147
+ Array(config.ignore_errors).any? do |pattern|
148
+ case pattern
149
+ when Regexp
150
+ message.match?(pattern)
151
+ else
152
+ message.include?(pattern.to_s)
153
+ end
154
+ end
155
+ end
156
+
157
+ def configured?
158
+ !config.nil? && !config.key.to_s.strip.empty?
159
+ end
160
+
161
+ def config
162
+ @config
163
+ end
164
+
165
+ def detect_environment
166
+ ENV["VYBESEC_ENV"] || ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "production"
167
+ end
168
+
169
+ def detect_server_platform
170
+ return "vercel" if ENV["VERCEL"]
171
+ return "railway" if ENV["RAILWAY_ENVIRONMENT"]
172
+ return "render" if ENV["RENDER"]
173
+ return "fly" if ENV["FLY_APP_NAME"]
174
+ return "replit" if ENV["REPL_ID"]
175
+
176
+ "unknown"
177
+ end
178
+
179
+ def debug_log(message)
180
+ warn(message) if config&.debug
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,47 @@
1
+ module Vybesec
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ status, headers, body = @app.call(env)
9
+
10
+ if status.to_i >= 500
11
+ Vybesec.capture_exception(
12
+ RuntimeError.new("#{env['REQUEST_METHOD']} #{env['PATH_INFO']} returned #{status}"),
13
+ route: env['PATH_INFO'],
14
+ method: env['REQUEST_METHOD'],
15
+ status_code: status.to_i,
16
+ request_body: request_body(env),
17
+ tags: { 'capturedBy' => 'rack-middleware' },
18
+ )
19
+ end
20
+
21
+ [status, headers, body]
22
+ rescue StandardError => e
23
+ Vybesec.capture_exception(
24
+ e,
25
+ route: env['PATH_INFO'],
26
+ method: env['REQUEST_METHOD'],
27
+ status_code: 500,
28
+ request_body: request_body(env),
29
+ tags: { 'capturedBy' => 'rack-middleware' },
30
+ )
31
+ raise
32
+ end
33
+
34
+ private
35
+
36
+ def request_body(env)
37
+ input = env['rack.input']
38
+ return nil unless input.respond_to?(:read)
39
+
40
+ body = input.read
41
+ input.rewind if input.respond_to?(:rewind)
42
+ body
43
+ rescue StandardError
44
+ nil
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,29 @@
1
+ module Vybesec
2
+ module Scrubber
3
+ module_function
4
+
5
+ PATTERNS = [
6
+ [/sk-[a-zA-Z0-9]{20,}/, "[api-key]"],
7
+ [/pk_live_[a-zA-Z0-9]{20,}/, "[stripe-key]"],
8
+ [/whsec_[a-zA-Z0-9]{20,}/, "[webhook-secret]"],
9
+ [/Bearer\s+[a-zA-Z0-9\-_.]{20,}/, "Bearer [token]"],
10
+ [/eyJ[a-zA-Z0-9_-]{10,}\.[a-zA-Z0-9_-]{10,}/, "[jwt]"],
11
+ [/\b[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}\b/, "[email]"],
12
+ [/\b\d{4}[\s\-]?\d{4}[\s\-]?\d{4}[\s\-]?\d{4}\b/, "[card]"],
13
+ [/\b\d{3}-\d{2}-\d{4}\b/, "[ssn]"],
14
+ [/"password"\s*:\s*"[^"]+"/i, '"password":"[redacted]"'],
15
+ [/"secret"\s*:\s*"[^"]+"/i, '"secret":"[redacted]"'],
16
+ [/"token"\s*:\s*"[^"]+"/i, '"token":"[redacted]"'],
17
+ ].freeze
18
+
19
+ def scrub(value)
20
+ return value if value.nil? || value.empty?
21
+
22
+ output = value.dup
23
+ PATTERNS.each do |pattern, replacement|
24
+ output.gsub!(pattern, replacement)
25
+ end
26
+ output
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Vybesec
2
+ VERSION = "0.1.1"
3
+ end
data/lib/vybesec.rb ADDED
@@ -0,0 +1,4 @@
1
+ require_relative "vybesec/version"
2
+ require_relative "vybesec/scrubber"
3
+ require_relative "vybesec/client"
4
+ require_relative "vybesec/middleware"
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vybesec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - VybeSec
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-03-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Capture Ruby server exceptions and send them to VybeSec ingest.
14
+ email:
15
+ - hello@vybesec.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE
21
+ - README.md
22
+ - lib/vybesec.rb
23
+ - lib/vybesec/client.rb
24
+ - lib/vybesec/middleware.rb
25
+ - lib/vybesec/scrubber.rb
26
+ - lib/vybesec/version.rb
27
+ homepage: https://vybesec.com
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '2.6'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.0.3.1
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: VybeSec server monitoring SDK for Ruby
50
+ test_files: []