mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-30 01:04:05 +09:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94692026d3 | ||
|
|
0672673916 | ||
|
|
5667262d1c |
No files matched your search
@@ -16,7 +16,7 @@ module RestrictedHTTP
|
|||||||
|
|
||||||
def private_ip?(ip)
|
def private_ip?(ip)
|
||||||
IPAddr.new(ip).then do |ipaddr|
|
IPAddr.new(ip).then do |ipaddr|
|
||||||
ipaddr.private? || ipaddr.loopback? || LOCAL_IP.include?(ipaddr)
|
ipaddr.private? || ipaddr.loopback? || ipaddr.link_local? || ipaddr.ipv4_mapped? || LOCAL_IP.include?(ipaddr)
|
||||||
end
|
end
|
||||||
rescue IPAddr::InvalidAddressError
|
rescue IPAddr::InvalidAddressError
|
||||||
true
|
true
|
||||||
|
|||||||
@@ -21,6 +21,28 @@ class Opengraph::LocationTest < ActiveSupport::TestCase
|
|||||||
assert_equal [ "is not public" ], location.errors[:url]
|
assert_equal [ "is not public" ], location.errors[:url]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "link-local addresses are blocked" do
|
||||||
|
Resolv.stubs(:getaddress).with("metadata.internal").returns("169.254.169.254")
|
||||||
|
|
||||||
|
location = Opengraph::Location.new("https://metadata.internal")
|
||||||
|
assert_not location.valid?
|
||||||
|
assert_equal [ "is not public" ], location.errors[:url]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "IPv6 addresses mapped to IPv4 addresses are blocked" do
|
||||||
|
Resolv.stubs(:getaddress).with("metadata.internal").returns("::ffff:192.168.1.1")
|
||||||
|
|
||||||
|
location = Opengraph::Location.new("https://metadata.internal")
|
||||||
|
assert_not location.valid?
|
||||||
|
assert_equal [ "is not public" ], location.errors[:url]
|
||||||
|
|
||||||
|
Resolv.stubs(:getaddress).with("metadata.internal").returns("::ffff:c0a8:0101")
|
||||||
|
|
||||||
|
location = Opengraph::Location.new("https://metadata.internal")
|
||||||
|
assert_not location.valid?
|
||||||
|
assert_equal [ "is not public" ], location.errors[:url]
|
||||||
|
end
|
||||||
|
|
||||||
test "avoid reading file urls when expecting HTML" do
|
test "avoid reading file urls when expecting HTML" do
|
||||||
large_file = Opengraph::Location.new("https://www.example.com/100gb.zip")
|
large_file = Opengraph::Location.new("https://www.example.com/100gb.zip")
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user