|
15 | 15 | end |
16 | 16 |
|
17 | 17 | context 'with error on webhook' do |
18 | | - it 'raises' do |
| 18 | + it 'reports to Sentry with sanitized URL' do |
| 19 | + allow(Sentry).to receive(:set_tags) |
| 20 | + allow(Sentry).to receive(:set_extras) |
19 | 21 | allow(Sentry).to receive(:capture_message) |
20 | 22 | stub_request(:post, web_hook_url).to_return(status: 500, body: "error") |
21 | 23 |
|
22 | 24 | job.perform_now |
| 25 | + |
| 26 | + expect(Sentry).to have_received(:set_extras).with(web_hook_url: "https://domaine.fr/callback_url") |
23 | 27 | expect(Sentry).to have_received(:capture_message) |
24 | 28 | end |
25 | 29 | end |
26 | 30 |
|
27 | | - context 'SSRF protection' do |
28 | | - context 'when webhook URL resolves to a private IP' do |
29 | | - let(:web_hook_url) { "https://domaine.fr/callback_url" } |
30 | | - |
31 | | - it 'does not make the HTTP request when DNS resolves to a private IP' do |
32 | | - stub = stub_request(:post, web_hook_url).to_return(status: 200, body: "success") |
33 | | - allow(Resolv).to receive(:getaddresses).with('domaine.fr').and_return(['10.0.0.1']) |
34 | | - |
35 | | - job.perform_now |
36 | | - expect(stub).not_to have_been_requested |
37 | | - end |
38 | | - |
39 | | - it 'does not make the HTTP request when DNS resolves to localhost' do |
40 | | - stub = stub_request(:post, web_hook_url).to_return(status: 200, body: "success") |
41 | | - allow(Resolv).to receive(:getaddresses).with('domaine.fr').and_return(['127.0.0.1']) |
42 | | - |
43 | | - job.perform_now |
44 | | - expect(stub).not_to have_been_requested |
45 | | - end |
46 | | - |
47 | | - it 'does not make the HTTP request when DNS resolves to link-local' do |
48 | | - stub = stub_request(:post, web_hook_url).to_return(status: 200, body: "success") |
49 | | - allow(Resolv).to receive(:getaddresses).with('domaine.fr').and_return(['169.254.169.254']) |
| 31 | + context 'when webhook URL contains query params' do |
| 32 | + let(:web_hook_url) { "https://domaine.fr/callback_url?token=secret123" } |
50 | 33 |
|
51 | | - job.perform_now |
52 | | - expect(stub).not_to have_been_requested |
53 | | - end |
54 | | - end |
55 | | - |
56 | | - context 'when webhook URL resolves to a public IP' do |
57 | | - let(:web_hook_url) { "https://domaine.fr/callback_url" } |
| 34 | + it 'strips query params from Sentry logs' do |
| 35 | + allow(Sentry).to receive(:set_tags) |
| 36 | + allow(Sentry).to receive(:set_extras) |
| 37 | + allow(Sentry).to receive(:capture_message) |
| 38 | + stub_request(:post, web_hook_url).to_return(status: 500, body: "error") |
58 | 39 |
|
59 | | - it 'makes the HTTP request normally' do |
60 | | - stub = stub_request(:post, web_hook_url).to_return(status: 200, body: "success") |
61 | | - allow(Resolv).to receive(:getaddresses).with('domaine.fr').and_return(['93.184.216.34']) |
| 40 | + job.perform_now |
62 | 41 |
|
63 | | - job.perform_now |
64 | | - expect(stub).to have_been_requested |
65 | | - end |
| 42 | + expect(Sentry).to have_received(:set_extras).with(web_hook_url: "https://domaine.fr/callback_url") |
66 | 43 | end |
67 | 44 | end |
68 | 45 | end |
|
0 commit comments