Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
36fe84c4
Unverified
Commit
36fe84c4
authored
3 years ago
by
Noah Moss
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Expand GeoJSON validation to all link-local addresses (#19164)
parent
a287a4fb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/api/geojson.clj
+10
-7
10 additions, 7 deletions
src/metabase/api/geojson.clj
test/metabase/api/geojson_test.clj
+17
-1
17 additions, 1 deletion
test/metabase/api/geojson_test.clj
with
27 additions
and
8 deletions
src/metabase/api/geojson.clj
+
10
−
7
View file @
36fe84c4
...
...
@@ -8,7 +8,7 @@
[
ring.util.codec
:as
rc
]
[
ring.util.response
:as
rr
]
[
schema.core
:as
s
])
(
:import
java.net
.
URL
(
:import
[
java.net
InetAddress
URL
]
org.apache.commons.io.input.ReaderInputStream
))
(
def
^
:private
CustomGeoJSON
...
...
@@ -36,13 +36,16 @@
(
tru
"URLs referring to hosts that supply internal hosting metadata are prohibited."
)))
(
def
^
:private
invalid-hosts
#
{
"169.254.169.254"
; internal metadata for AWS, OpenStack, and Azure
"metadata.google.internal"
})
; internal metadata for GCP
#
{
"metadata.google.internal"
})
; internal metadata for GCP
(
defn-
valid-host?
[
^
URL
url
]
(
not
(
invalid-hosts
(
.getHost
url
))))
(
let
[
host
(
.getHost
url
)
host->url
(
fn
[
host
]
(
URL.
(
str
"http://"
host
)))
base-url
(
host->url
(
.getHost
url
))]
(
and
(
not-any?
(
fn
[
invalid-url
]
(
.equals
^
URL
base-url
invalid-url
))
(
map
host->url
invalid-hosts
))
(
not
(
.isLinkLocalAddress
(
InetAddress/getByName
host
))))))
(
defn-
valid-protocol?
[
^
URL
url
]
...
...
@@ -52,8 +55,8 @@
[
url-string
]
(
try
(
let
[
url
(
URL.
url-string
)]
(
and
(
valid-
host
?
url
)
(
valid-
protocol
?
url
)))
(
and
(
valid-
protocol
?
url
)
(
valid-
host
?
url
)))
(
catch
Throwable
e
(
throw
(
ex-info
(
invalid-location-msg
)
{
:status-code
400
,
:url
url-string
}
e
)))))
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/geojson_test.clj
+
17
−
1
View file @
36fe84c4
...
...
@@ -35,19 +35,35 @@
(
deftest
validate-geojson-test
(
testing
"It validates URLs and files appropriately"
(
let
[
examples
{
;;
Prohibited hosts (see explanation in source file)
(
let
[
examples
{
;;
Internal metadata for GCP
"metadata.google.internal"
false
"https://metadata.google.internal"
false
"//metadata.google.internal"
false
;; Link-local addresses (internal metadata for AWS, OpenStack, and Azure)
"http://169.254.0.0"
false
"http://fe80::"
false
"169.254.169.254"
false
"http://169.254.169.254/secret-stuff.json"
false
;; alternate IPv4 encodings (hex, octal, integer)
"http://0xa9fea9fe"
false
"https://0xa9fea9fe"
false
"http://0xA9FEA9FE"
false
"http://0xa9.0xfe.0xa9.0xfe"
false
"http://0XA9.0XFE.0xA9.0XFE"
false
"http://0xa9fea9fe/secret-stuff.json"
false
"http://025177524776"
false
"http://0251.0376.0251.0376"
false
"http://2852039166"
false
;; Prohibited protocols
"ftp://example.com/rivendell.json"
false
"example.com/rivendell.json"
false
"jar:file:test.jar!/test.json"
false
;; Acceptable URLs
"http://example.com/"
true
"https://example.com/"
true
"http://example.com/rivendell.json"
true
"http://192.0.2.0"
true
"http://0xc0000200"
true
;; Resources (files on classpath) are valid
"c3p0.properties"
true
;; Other files are not
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment