completion-kit 0.5.26 → 0.5.28

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 312676093066234886bea6d8cb908e669d045dfdb02660b2872266c6baeb3e59
4
- data.tar.gz: '0974b8805e344059b9c063d7979b61ab9c08b2182a5438f230386d2244b29d91'
3
+ metadata.gz: e5b7b1f667eb85b17d7ae6302671129a1e68821bffd1a83f667a7336776f5927
4
+ data.tar.gz: 2f0e3642574d60e69a466bf0fe097c3287a104ba2a049c33afa6462a83dccaf2
5
5
  SHA512:
6
- metadata.gz: 2ab3528c3521917d7309bb95b8639645e17cfa28b250245cf33eefd6d9220548c7424592180ab6c911ae2bf181a5443a77395f8e4434e1c9043510fa67827ba9
7
- data.tar.gz: 6b8ae35b53a6a82d164155978a324f1915211153818b90e53e808d1d6368f7345e27a1fef185c98f275d9f729c654f48e21dd83811c325e138abb96d72d42062
6
+ metadata.gz: 19bc73fa1f422a5bee002c10681966fa263fe8a69f8928bb48d9630d53feca65721cbc81b3b3415c4dac9d60dc67a616dde7ac1d5e3154b2aa136b73e25a7077
7
+ data.tar.gz: 5ba36b81ebc2a7df4421423dc8614c624c73f8dde0477bf4a579e914a36ed7c36821840f8c2aed963eb04a50cf840db14119a81a794a251576026731648e49d8
@@ -22,7 +22,7 @@ module CompletionKit
22
22
  ActiveSupport::SecurityUtils.secure_compare(u, cfg.username) &
23
23
  ActiveSupport::SecurityUtils.secure_compare(p, cfg.password)
24
24
  end
25
- elsif Rails.env.production?
25
+ elsif !Rails.env.local?
26
26
  render plain: "CompletionKit authentication not configured. See README for setup instructions.",
27
27
  status: :forbidden
28
28
  end
@@ -35,7 +35,8 @@ module CompletionKit
35
35
  rescue ActiveRecord::RecordInvalid, ActiveRecord::InvalidForeignKey => e
36
36
  render json: jsonrpc_error(request_body.dig("id"), -32602, e.message), status: :ok
37
37
  rescue StandardError => e
38
- render json: jsonrpc_error(request_body.dig("id"), -32603, e.message), status: :ok
38
+ Rails.error.report(e, handled: true, context: { controller: "CompletionKit::McpController" })
39
+ render json: jsonrpc_error(request_body.dig("id"), -32603, "Internal error"), status: :ok
39
40
  end
40
41
 
41
42
  def destroy
@@ -1,3 +1,6 @@
1
+ require "ipaddr"
2
+ require "resolv"
3
+
1
4
  module CompletionKit
2
5
  class ProviderCredential < ApplicationRecord
3
6
  include Turbo::Broadcastable
@@ -24,6 +27,7 @@ module CompletionKit
24
27
 
25
28
  validates :provider, presence: true, inclusion: { in: PROVIDERS }
26
29
  validates :provider, tenant_scoped_uniqueness: true
30
+ validate :api_endpoint_not_internal
27
31
 
28
32
  after_save :enqueue_discovery
29
33
 
@@ -131,5 +135,33 @@ module CompletionKit
131
135
  CompletionKit::Engine.warm_routes!
132
136
  CompletionKit::ApplicationController.render(partial: partial, locals: locals)
133
137
  end
138
+
139
+ def api_endpoint_not_internal
140
+ return if api_endpoint.blank?
141
+
142
+ uri = safe_http_uri(api_endpoint)
143
+ unless uri
144
+ errors.add(:api_endpoint, "must be a valid http or https URL")
145
+ return
146
+ end
147
+
148
+ if endpoint_addresses(uri.host).any? { |ip| ip.private? || ip.link_local? }
149
+ errors.add(:api_endpoint, "must not point at a private or internal address")
150
+ end
151
+ end
152
+
153
+ def safe_http_uri(value)
154
+ uri = URI.parse(value.to_s.strip)
155
+ uri if uri.is_a?(URI::HTTP) && uri.host.present?
156
+ rescue URI::InvalidURIError
157
+ nil
158
+ end
159
+
160
+ def endpoint_addresses(host)
161
+ bare = host.delete_prefix("[").delete_suffix("]")
162
+ [IPAddr.new(bare)]
163
+ rescue IPAddr::InvalidAddressError
164
+ Resolv.getaddresses(host).map { |addr| IPAddr.new(addr) }
165
+ end
134
166
  end
135
167
  end
@@ -1,3 +1,3 @@
1
1
  module CompletionKit
2
- VERSION = "0.5.26"
2
+ VERSION = "0.5.28"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: completion-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.26
4
+ version: 0.5.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Bastin