Skip to content

Commit b2eb99e

Browse files
Guillaume Felicianoamro
authored andcommitted
Ensure we raise if the root domain changed and it was not an expected behavior
1 parent f71acf2 commit b2eb99e

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/gibbon/api_request.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ def api_url
194194

195195
def base_api_url
196196
computed_api_endpoint = "https://#{get_data_center_from_api_key(self.api_key)}api.mailchimp.com"
197+
raise Gibbon::GibbonError, "SSRF attempt" unless URI(computed_api_endpoint).host.include?("api.mailchimp.com")
198+
197199
"#{self.api_endpoint || computed_api_endpoint}/3.0/"
198200
end
199201
end

spec/gibbon/gibbon_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@
162162
@request = Gibbon::APIRequest.new(builder: @gibbon)
163163
expect {@request.validate_api_key}.not_to raise_error
164164
end
165+
166+
it "raises with a valid SSRF attack" do
167+
@api_key = "-attacker.net/test/?"
168+
@gibbon.api_key = @api_key
169+
expect {@gibbon.try.retrieve}.not_to raise_error
170+
end
165171
end
166172

167173
describe "class variables" do
@@ -213,7 +219,7 @@
213219
it "set debug on new instances" do
214220
expect(Gibbon::Request.new.debug).to eq(Gibbon::Request.debug)
215221
end
216-
222+
217223
it "set faraday_adapter on new instances" do
218224
expect(Gibbon::Request.new.faraday_adapter).to eq(Gibbon::Request.faraday_adapter)
219225
end

0 commit comments

Comments
 (0)