koderift-rails 2.0.0 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9c83f5ae85e74957769db72695555fbdd39aebef940ecb97b7cf1dda72d75c0
4
- data.tar.gz: d27d1449f36d00606d187eed46783a6cbcd6df03ad1f2ee8cf515f834d294735
3
+ metadata.gz: b77962b847bf6127f3029ab4cab2eb3f71ae3cf0d0041c6d2df6ad1108449c7e
4
+ data.tar.gz: cc0a1ab9373ca3544bf3d9b48bf08ea1afa269236d4385e9873a139ea258fb0f
5
5
  SHA512:
6
- metadata.gz: 43e553f25047fc9501be705793df7e7d9b82ec5ecd17850ca8b45b07baacb4e52dd954611a11b580284aedfb6abc070a9ad139482aba6210b63432ceee3c6c11
7
- data.tar.gz: e55b1666a9e531b7a4ca9e1f02acaeb4086ef17b65cd0aee6750fd3d641106b248e5027fa083d0f11f95797409688fff9618ed09d8a886e20b6e12ac71e98009
6
+ metadata.gz: 274e3e08f2d325ef30063547658668b955eb32607c6705829c5de531b8ac40d63701d199a3fffb9d537f3298a29816dd491ba897a0ec93dc0237eebaa2964b24
7
+ data.tar.gz: d409cd77d3f77b28d86fb526ddff9b096314b8b12e4af3e1e687b281a98d811fabcb775b164eed5a785433ee6455697faabd1a25c3cb5953a8c8fadd3ccb1425
data/CHANGELOG.md CHANGED
@@ -6,6 +6,38 @@ This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
  Releases before 1.3.4 were installed from git and were never published to
7
7
  RubyGems; they are listed for continuity.
8
8
 
9
+ ## [2.1.0] - 2026-11-06
10
+
11
+ Security fix: the Browser RUM meta tag no longer publishes your project token.
12
+
13
+ ### Security
14
+ - `koderift_rum_meta_tag` used to render `config.project_token` into page HTML.
15
+ That token is the log agent's ingest secret, so anyone reading your page
16
+ source could use it to send log lines to your Koderift project, including
17
+ lines that count against its log quota. The tag now renders only the new
18
+ `config.rum_token`, a public token that can only send browser RUM data.
19
+ - If you rendered the RUM tag on 2.0 or older, treat your project token as
20
+ public. Once this version is deployed with `rum_token` set, rotate the ingest
21
+ token in Koderift (Log Analytics settings, "Rotate ingest token"), then update
22
+ `webhook_url` in the agent's `agent.yml` and `KODERIFT_PROJECT_TOKEN` in your
23
+ app, and restart the agent.
24
+
25
+ ### Added
26
+ - `config.rum_token`: your project's public RUM token, from the Log Analytics
27
+ setup page in Koderift. It starts with `rum_`.
28
+
29
+ ### Changed
30
+ - **Action needed if you use Browser RUM:** set `config.rum_token`. Without it
31
+ the meta tag renders nothing, and the gem logs one warning per process the
32
+ first time a page renders it. There is deliberately no fallback to
33
+ `project_token`. The tag also refuses a `rum_token` equal to `project_token`.
34
+
35
+ ### Notes
36
+ - Koderift keeps accepting RUM data sent with the old token until
37
+ 1 February 2027, so pages not yet upgraded keep reporting until then.
38
+ - `project_token` is still required to turn the gem on. The gem never sends it
39
+ anywhere; the log agent uses its own copy in `agent.yml`.
40
+
9
41
  ## [2.0.0] - 2026-11-04
10
42
 
11
43
  Manual error reporting, with a Sentry-compatible API.
data/README.md CHANGED
@@ -12,7 +12,7 @@ Requires Ruby >= 2.7 and Rails 7.1-8.x.
12
12
  Add to your `Gemfile`:
13
13
 
14
14
  ```ruby
15
- gem 'koderift-rails', '~> 2.0'
15
+ gem 'koderift-rails', '~> 2.1'
16
16
  ```
17
17
 
18
18
  Run `bundle install`. Lograge is a dependency of this gem and is installed
@@ -32,7 +32,37 @@ end
32
32
  ```
33
33
 
34
34
  Set `KODERIFT_PROJECT_TOKEN` in your environment to the token from your
35
- project's Log Analytics settings page in Koderift.
35
+ project's Log Analytics settings page in Koderift. It is the log agent's
36
+ ingest secret: keep it out of your repository and your page HTML.
37
+
38
+ ## Browser RUM
39
+
40
+ To collect Core Web Vitals and JS error counts from real browsers, set your
41
+ project's public RUM token (from the Log Analytics setup page; it starts with
42
+ `rum_`) and add the meta tag and snippet inside your layout's `<head>`:
43
+
44
+ ```ruby
45
+ Koderift::Rails.configure do |config|
46
+ config.project_token = ENV['KODERIFT_PROJECT_TOKEN']
47
+ config.rum_token = 'rum_...'
48
+ end
49
+ ```
50
+
51
+ ```erb
52
+ <%= koderift_rum_meta_tag %>
53
+ <script src="https://<your Koderift host>/ingest/rum.js" async defer></script>
54
+ ```
55
+
56
+ The meta tag publishes `rum_token` only. It can only send browser RUM data, so
57
+ it is safe in page HTML and safe to commit. The gem never renders
58
+ `project_token`, and it refuses a `rum_token` equal to it. Without a
59
+ `rum_token` the tag renders nothing and the gem logs one warning per process.
60
+ Set `config.rum_enabled = false` for API-only apps.
61
+
62
+ Upgrading from 2.0 or older with RUM in use? Those versions published
63
+ `project_token` in the meta tag. Set `rum_token`, deploy, then rotate the
64
+ ingest token in Koderift (Log Analytics settings) and update `webhook_url` in
65
+ the agent's `agent.yml`. See the [changelog](CHANGELOG.md).
36
66
 
37
67
  ## What it captures
38
68
 
@@ -7,6 +7,14 @@ module Koderift
7
7
  # Set from an environment variable in the initializer.
8
8
  attr_accessor :project_token
9
9
 
10
+ # Public token for Browser RUM, rendered into page HTML by
11
+ # koderift_rum_meta_tag. It can only send browser RUM data, so it is safe
12
+ # to publish (and to commit). Copy it from your project's Log Analytics
13
+ # setup page in Koderift; it starts with "rum_". Never set it to
14
+ # project_token: that is the log agent's ingest secret, and anyone who
15
+ # reads it from your page source can send log lines to your project.
16
+ attr_accessor :rum_token
17
+
10
18
  # Lambda called with the controller instance to get the current user.
11
19
  # Default tries common patterns. Override if your app is different.
12
20
  # Example: ->(controller) { controller.current_user }
@@ -65,6 +73,7 @@ module Koderift
65
73
 
66
74
  def initialize
67
75
  @project_token = nil
76
+ @rum_token = nil
68
77
  @current_user = default_current_user
69
78
  @filter_params = %w[
70
79
  password password_confirmation
@@ -3,6 +3,18 @@
3
3
  module Koderift
4
4
  module Rails
5
5
  module RumHelper
6
+ MISSING_RUM_TOKEN_WARNING =
7
+ '[Koderift] Browser RUM is off: koderift_rum_meta_tag renders nothing until ' \
8
+ 'config.rum_token is set. Since koderift-rails 2.1 the tag no longer publishes ' \
9
+ 'config.project_token, which is a secret. Copy the public RUM token (it starts ' \
10
+ "with rum_) from your project's Log Analytics setup page in Koderift, or set " \
11
+ 'config.rum_enabled = false.'
12
+
13
+ SECRET_RUM_TOKEN_WARNING =
14
+ '[Koderift] Browser RUM is off: config.rum_token is set to your project token, ' \
15
+ 'which is a secret and must not appear in page HTML. Use the public RUM token ' \
16
+ "(it starts with rum_) from your project's Log Analytics setup page in Koderift."
17
+
6
18
  # Renders the meta tag that rum.js reads for initialisation.
7
19
  # Place once inside <head> in your application layout.
8
20
  #
@@ -11,24 +23,68 @@ module Koderift
11
23
  #
12
24
  # Renders:
13
25
  # <meta name="koderift-rum-token"
14
- # content="abc123"
26
+ # content="rum_abc123"
15
27
  # data-rum-sampling-rate="0.1"
16
28
  # data-environment="production">
17
29
  #
18
- # Returns an empty string when RUM is disabled or no token is configured.
30
+ # Publishes config.rum_token only, never config.project_token. Returns an
31
+ # empty string when RUM is disabled or there is no publishable token.
19
32
  def koderift_rum_meta_tag
20
33
  config = Koderift::Rails.configuration
21
- return ''.html_safe unless config.rum_enabled && config.project_token.present?
34
+ return ''.html_safe unless config.rum_enabled
35
+
36
+ token = RumHelper.publishable_rum_token(config)
37
+ return ''.html_safe unless token
22
38
 
23
39
  tag.meta(
24
40
  name: 'koderift-rum-token',
25
- content: config.project_token,
41
+ content: token,
26
42
  data: {
27
43
  rum_sampling_rate: config.rum_sampling_rate.to_f,
28
44
  environment: (defined?(::Rails) && ::Rails.respond_to?(:env) ? ::Rails.env.to_s : 'production')
29
45
  }
30
46
  )
31
47
  end
48
+
49
+ class << self
50
+ # The token the meta tag may publish, or nil. Up to 2.0 the tag published
51
+ # project_token, the log agent's ingest secret. It never does now, and a
52
+ # rum_token equal to it is refused for the same reason. There is
53
+ # deliberately no fallback: an app that set up RUM before 2.1 and has
54
+ # not set rum_token gets one warning per process instead.
55
+ def publishable_rum_token(config)
56
+ token = config.rum_token.to_s
57
+ secret = config.project_token.to_s
58
+
59
+ if token.empty?
60
+ warn_once(MISSING_RUM_TOKEN_WARNING) unless secret.empty?
61
+ return nil
62
+ end
63
+
64
+ if token == secret
65
+ warn_once(SECRET_RUM_TOKEN_WARNING)
66
+ return nil
67
+ end
68
+
69
+ token
70
+ end
71
+
72
+ def reset_warnings!
73
+ @warned = false
74
+ end
75
+
76
+ private
77
+
78
+ def warn_once(message)
79
+ return if @warned
80
+
81
+ @warned = true
82
+ logger = defined?(::Rails) && ::Rails.respond_to?(:logger) ? ::Rails.logger : nil
83
+ logger&.warn(message)
84
+ rescue StandardError
85
+ nil
86
+ end
87
+ end
32
88
  end
33
89
  end
34
90
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Koderift
4
4
  module Rails
5
- VERSION = '2.0.0'
5
+ VERSION = '2.1.0'
6
6
  end
7
7
  end
@@ -29,6 +29,7 @@ module Koderift
29
29
  Capture.reset_rate_limiter!
30
30
  Scope.reset!
31
31
  Breadcrumbs.clear
32
+ RumHelper.reset_warnings!
32
33
  end
33
34
 
34
35
  # ---------------------------------------------------------------- capture
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koderift-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koderift