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 +4 -4
- data/lib/noticed/api_client.rb +31 -1
- data/lib/noticed/version.rb +1 -1
- data/lib/noticed.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ecc868a3bd5a4a148807346b8098f98adc8c3d5eb32a06ae715ae3ba2cca97fc
|
|
4
|
+
data.tar.gz: 49d58efb90e42b62307fb7935d742d18e6e55819eabf3ba8cc6b8aad194e325b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 423d351810b3aa6105f911986c4fcd3f8984e54f5590673d02045062ca5af82e7bb67e33496d9375fd536efae423d1c377a9c903ec467fe37bdf212b418c60bf
|
|
7
|
+
data.tar.gz: 31ee2de6daa6e33026411b94cccf9eeb3af002f9e55be727b910c773b5c50c22a9d37043e57264f59c5948d1782f7bbee861032bedd10cc5604bc1ab80a5b25e
|
data/lib/noticed/api_client.rb
CHANGED
|
@@ -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
|
data/lib/noticed/version.rb
CHANGED
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
|