noticed 3.1.0 → 3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a62b2258520a1d287a6ab2ff9b73288e37ebd7d4b18994c0b13bcfb591e9440
4
- data.tar.gz: ecf9a251b05942f6b32c3730b923d59e16e4eb9de169e361b1ce0cb2989750f1
3
+ metadata.gz: ecc868a3bd5a4a148807346b8098f98adc8c3d5eb32a06ae715ae3ba2cca97fc
4
+ data.tar.gz: 49d58efb90e42b62307fb7935d742d18e6e55819eabf3ba8cc6b8aad194e325b
5
5
  SHA512:
6
- metadata.gz: 75edf989bdb4bc2fd7ee445f2852107fdfd629696affeae51d7e3d407ebdd97669b5d11bf8bbc79d92c4dc22dfde7bddcdd528c6f52c0230e1b169ef716d95cb
7
- data.tar.gz: d34cdd0a3e905188d6efe9852b1b199148e9b4e02e0677d446fbf48ab94fb98d6bc87bf9b7917280649b6182f5e7ef9e9d64af0cd43ef1db4ea45b23d4517225
6
+ metadata.gz: 423d351810b3aa6105f911986c4fcd3f8984e54f5590673d02045062ca5af82e7bb67e33496d9375fd536efae423d1c377a9c903ec467fe37bdf212b418c60bf
7
+ data.tar.gz: 31ee2de6daa6e33026411b94cccf9eeb3af002f9e55be727b910c773b5c50c22a9d37043e57264f59c5948d1782f7bbee861032bedd10cc5604bc1ab80a5b25e
@@ -4,6 +4,18 @@ module Noticed
4
4
  module ApiClient
5
5
  extend ActiveSupport::Concern
6
6
 
7
+ # Webhook URLs whose path carries the credential. The first group is kept and the second is
8
+ # replaced with [FILTERED] in logs and error messages.
9
+ #
10
+ # Discord https://discord.com/api/webhooks/{id}/{token}[/slack|/github]
11
+ # Slack https://hooks.slack.com/services/T000/B000/{token}
12
+ # Microsoft Teams https://{tenant}.webhook.office.com/webhookb2/{group}@{tenant}/IncomingWebhook/... (everything after is filtered)
13
+ CREDENTIAL_PATHS = [
14
+ %r{(discord(?:app)?\.com/api/(?:v\d+/)?webhooks/\d+/)([^/]+)},
15
+ %r{(hooks\.slack\.com/(?:services/)?T[^/]+/B[^/]+/)([^/]+)},
16
+ %r{(/webhookb2/[^/]+/IncomingWebhook/)(.+)}
17
+ ]
18
+
7
19
  # Helper method for making POST requests from delivery methods
8
20
  #
9
21
  # Usage:
@@ -34,7 +46,7 @@ module Noticed
34
46
  end
35
47
 
36
48
  # Bodies aren't logged since they can contain credentials and access tokens
37
- logger.debug("POST #{url}")
49
+ logger.debug("POST #{ApiClient.filtered_url(url)}")
38
50
  response = http.request(request)
39
51
  logger.debug("Response: #{response.code}")
40
52
 
@@ -42,5 +54,23 @@ module Noticed
42
54
 
43
55
  response
44
56
  end
57
+
58
+ # Returns the URL with credentials replaced by [FILTERED], like Rails does for request parameters
59
+ #
60
+ # Noticed::ApiClient.filtered_url("https://discord.com/api/webhooks/123/abc?wait=true")
61
+ # # => "https://discord.com/api/webhooks/123/[FILTERED]?wait=true"
62
+ def self.filtered_url(url)
63
+ path, query = url.to_s.split("?", 2)
64
+ CREDENTIAL_PATHS.each { |pattern| path = path.sub(pattern) { "#{$1}[FILTERED]" } }
65
+
66
+ if query
67
+ # Application's filter_parameters plus sig, the secret of Microsoft Teams Workflows URLs:
68
+ # https://prod-00.westus.logic.azure.com/workflows/{id}/triggers/manual/paths/invoke?api-version=...&sp=...&sv=...&sig={secret}
69
+ parameter_filter = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters + [:sig])
70
+ query = query.gsub(/([^&=]+)=([^&]*)/) { "#{$1}=#{parameter_filter.filter_param($1, $2)}" }
71
+ end
72
+
73
+ query ? "#{path}?#{query}" : path
74
+ end
45
75
  end
46
76
  end
@@ -1,3 +1,3 @@
1
1
  module Noticed
2
- VERSION = "3.1.0"
2
+ VERSION = "3.1.1"
3
3
  end
data/lib/noticed.rb CHANGED
@@ -35,10 +35,10 @@ module Noticed
35
35
 
36
36
  def initialize(response, url, args)
37
37
  @response = response
38
- @url = url
38
+ @url = ApiClient.filtered_url(url)
39
39
  @args = args
40
40
 
41
- super("POST request to #{url} returned #{response.code} response:\n#{response.body.inspect}")
41
+ super("POST request to #{@url} returned #{response.code} response:\n#{response.body.inspect}")
42
42
  end
43
43
  end
44
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noticed
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver