logstruct 0.1.8 → 0.1.9
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 95828f14e3935518654b94939f2cee577f296d454fa3666a8e5f1eb9ababb1dd
|
|
4
|
+
data.tar.gz: dcd8ff40d991a79573fe60e678ea85590b9597f1e0163f132f8eff79015a88ff
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 868f9dc4e320fbdf752b0e3b901280b5a972b9759592869587bf3673d905ddb3b554851c0dfe977eafe543be37b37105f9f759cccc8d06a009771585c931ce58
|
|
7
|
+
data.tar.gz: b8402c46a941a578261933249acddff294551d5fd5b1823ed54e48ce2f17ba1e760919a540ef38918706004093a1b3c0f5a89e16405037e4e86cbd6a114bc363
|
data/CHANGELOG.md
CHANGED
|
@@ -5,8 +5,18 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
8
10
|
### Changed
|
|
9
11
|
|
|
12
|
+
## [0.1.9] - 2026-01-23
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- **Fix**: ActiveJob integration handles Rails main event reporter subscribers
|
|
17
|
+
- **Fix**: Rack error handler avoids deprecated CSRF exception class on Rails main
|
|
18
|
+
- **CI**: Added Rails main daily integration run and updated Rails test matrix (7.1.6, 7.2.3, 8.0.4, 8.1.2)
|
|
19
|
+
|
|
10
20
|
## [0.1.8] - 2026-01-22
|
|
11
21
|
|
|
12
22
|
- **Fix**: Lograge custom options now appear in request logs
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require "active_support/log_subscriber"
|
|
4
5
|
require_relative "../../enums/source"
|
|
5
6
|
require_relative "../../enums/event"
|
|
6
7
|
require_relative "../../log/active_job"
|
|
@@ -10,7 +11,7 @@ module LogStruct
|
|
|
10
11
|
module Integrations
|
|
11
12
|
module ActiveJob
|
|
12
13
|
# Structured logging for ActiveJob
|
|
13
|
-
class LogSubscriber < ::
|
|
14
|
+
class LogSubscriber < ::ActiveSupport::LogSubscriber
|
|
14
15
|
extend T::Sig
|
|
15
16
|
|
|
16
17
|
sig { params(event: ::ActiveSupport::Notifications::Event).void }
|
|
@@ -25,8 +25,13 @@ module LogStruct
|
|
|
25
25
|
return nil unless config.integrations.enable_activejob
|
|
26
26
|
|
|
27
27
|
::ActiveSupport.on_load(:active_job) do
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if ::ActiveJob::LogSubscriber.respond_to?(:detach_from)
|
|
29
|
+
# Detach the default text formatter
|
|
30
|
+
::ActiveJob::LogSubscriber.detach_from :active_job
|
|
31
|
+
elsif ::ActiveSupport.respond_to?(:event_reporter)
|
|
32
|
+
reporter = ::ActiveSupport.event_reporter
|
|
33
|
+
reporter.unsubscribe(::ActiveJob::LogSubscriber) if reporter.respond_to?(:unsubscribe)
|
|
34
|
+
end
|
|
30
35
|
|
|
31
36
|
# Attach our structured formatter
|
|
32
37
|
Integrations::ActiveJob::LogSubscriber.attach_to :active_job
|
|
@@ -81,38 +81,40 @@ module LogStruct
|
|
|
81
81
|
::Rails.logger.warn(security_log)
|
|
82
82
|
|
|
83
83
|
[FORBIDDEN_STATUS, IP_SPOOF_HEADERS.dup, [IP_SPOOF_HTML]]
|
|
84
|
-
rescue ::ActionController::InvalidAuthenticityToken => invalid_auth_token_error
|
|
85
|
-
# Create a security log for CSRF error
|
|
86
|
-
security_log = Log::Security::CSRFViolation.new(
|
|
87
|
-
path: request.path,
|
|
88
|
-
http_method: request.method,
|
|
89
|
-
source_ip: request.remote_ip,
|
|
90
|
-
user_agent: request.user_agent,
|
|
91
|
-
referer: request.referer,
|
|
92
|
-
request_id: request.request_id,
|
|
93
|
-
message: invalid_auth_token_error.message,
|
|
94
|
-
timestamp: Time.now
|
|
95
|
-
)
|
|
96
|
-
LogStruct.error(security_log)
|
|
97
|
-
|
|
98
|
-
# Report to error reporting service and/or re-raise
|
|
99
|
-
context = extract_request_context(env, request)
|
|
100
|
-
LogStruct.handle_exception(invalid_auth_token_error, source: Source::Security, context: context)
|
|
101
|
-
|
|
102
|
-
# If handle_exception raised an exception then Rails will deal with it (e.g. config.exceptions_app)
|
|
103
|
-
# If we are only logging or reporting these security errors, then return a default response
|
|
104
|
-
[FORBIDDEN_STATUS, CSRF_HEADERS.dup, [CSRF_HTML]]
|
|
105
84
|
rescue => error
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
85
|
+
if csrf_error?(error)
|
|
86
|
+
# Create a security log for CSRF error
|
|
87
|
+
security_log = Log::Security::CSRFViolation.new(
|
|
88
|
+
path: request.path,
|
|
89
|
+
http_method: request.method,
|
|
90
|
+
source_ip: request.remote_ip,
|
|
91
|
+
user_agent: request.user_agent,
|
|
92
|
+
referer: request.referer,
|
|
93
|
+
request_id: request.request_id,
|
|
94
|
+
message: error.message,
|
|
95
|
+
timestamp: Time.now
|
|
96
|
+
)
|
|
97
|
+
LogStruct.error(security_log)
|
|
98
|
+
|
|
99
|
+
# Report to error reporting service and/or re-raise
|
|
100
|
+
context = extract_request_context(env, request)
|
|
101
|
+
LogStruct.handle_exception(error, source: Source::Security, context: context)
|
|
102
|
+
|
|
103
|
+
# If handle_exception raised an exception then Rails will deal with it (e.g. config.exceptions_app)
|
|
104
|
+
# If we are only logging or reporting these security errors, then return a default response
|
|
105
|
+
[FORBIDDEN_STATUS, CSRF_HEADERS.dup, [CSRF_HTML]]
|
|
106
|
+
else
|
|
107
|
+
# Extract request context for error reporting
|
|
108
|
+
context = extract_request_context(env, request)
|
|
109
|
+
|
|
110
|
+
# Create and log a structured exception with request context
|
|
111
|
+
exception_log = Log.from_exception(Source::Rails, error, context)
|
|
112
|
+
LogStruct.error(exception_log)
|
|
113
|
+
|
|
114
|
+
# Re-raise any standard errors to let Rails or error reporter handle it.
|
|
115
|
+
# Rails will also log the request details separately
|
|
116
|
+
raise error
|
|
117
|
+
end
|
|
116
118
|
end
|
|
117
119
|
end
|
|
118
120
|
|
|
@@ -146,6 +148,13 @@ module LogStruct
|
|
|
146
148
|
{error_extracting_context: error.message}
|
|
147
149
|
end
|
|
148
150
|
|
|
151
|
+
sig { params(error: StandardError).returns(T::Boolean) }
|
|
152
|
+
def csrf_error?(error)
|
|
153
|
+
error_name = error.class.name
|
|
154
|
+
error_name == "ActionController::InvalidAuthenticityToken" ||
|
|
155
|
+
error_name == "ActionController::InvalidCrossOriginRequest"
|
|
156
|
+
end
|
|
157
|
+
|
|
149
158
|
sig { params(configured_proxies: T.untyped).returns(T.untyped) }
|
|
150
159
|
def normalized_trusted_proxies(configured_proxies)
|
|
151
160
|
if configured_proxies.nil? || (configured_proxies.respond_to?(:empty?) && configured_proxies.empty?)
|
data/lib/log_struct/version.rb
CHANGED