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
6fafcb34
Unverified
Commit
6fafcb34
authored
1 year ago
by
Jerry Huang
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Backend validation for landing-page to disallow external URLs (#37551)
* landing-page backend validation * fix spacing
parent
3ef4d5df
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/public_settings.clj
+19
-1
19 additions, 1 deletion
src/metabase/public_settings.clj
test/metabase/public_settings_test.clj
+50
-1
50 additions, 1 deletion
test/metabase/public_settings_test.clj
with
69 additions
and
2 deletions
src/metabase/public_settings.clj
+
19
−
1
View file @
6fafcb34
(
ns
metabase.public-settings
(
:require
[
clojure.java.io
:as
io
]
[
clojure.string
:as
str
]
[
java-time.api
:as
t
]
[
metabase.api.common
:as
api
]
...
...
@@ -257,12 +258,29 @@
:visibility
:public
:audit
:getter
)
(
defn-
coerce-to-relative-url
"Get the path of a given URL if the URL contains an origin.
Otherwise make the landing-page a relative path."
[
landing-page
]
(
cond
(
u/url?
landing-page
)
(
->
landing-page
io/as-url
.getPath
)
(
empty?
landing-page
)
""
(
not
(
str/starts-with?
landing-page
"/"
))
(
str
"/"
landing-page
)
:else
landing-page
))
(
defsetting
landing-page
(
deferred-tru
"Default page to show people when they log in."
)
:visibility
:public
:type
:string
:default
""
:audit
:getter
)
:audit
:getter
:setter
(
fn
[
new-landing-page
]
(
when
new-landing-page
;; If the landing page is a valid URL or mailto, sms, or file, then check with if site-url has the same origin.
(
when
(
and
(
or
(
re-matches
#
"^(mailto|sms|file):(.*)"
new-landing-page
)
(
u/url?
new-landing-page
))
(
not
(
str/starts-with?
new-landing-page
(
site-url
))))
(
throw
(
ex-info
(
tru
"This field must be a relative URL."
)
{
:status-code
400
}))))
(
setting/set-value-of-type!
:string
:landing-page
(
coerce-to-relative-url
new-landing-page
))))
(
defsetting
enable-public-sharing
(
deferred-tru
"Enable admins to create publicly viewable links (and embeddable iframes) for Questions and Dashboards?"
)
...
...
This diff is collapsed.
Click to expand it.
test/metabase/public_settings_test.clj
+
50
−
1
View file @
6fafcb34
...
...
@@ -184,7 +184,6 @@
(
is
(
=
false
(
public-settings/redirect-all-requests-to-https
)))))))))
(
deftest
cloud-gateway-ips-test
(
mt/with-temp-env-var-value
[
mb-cloud-gateway-ips
"1.2.3.4,5.6.7.8"
]
(
with-redefs
[
premium-features/is-hosted?
(
constantly
true
)]
...
...
@@ -301,3 +300,53 @@
(
public-settings/help-link-custom-destination!
"http://www.metabase.com"
)))
(
is
(
=
nil
(
public-settings/help-link-custom-destination
))))))
(
deftest
landing-page-setting-test
(
testing
"should return relative url for valid inputs"
(
public-settings/landing-page!
""
)
(
is
(
=
""
(
public-settings/landing-page
)))
(
public-settings/landing-page!
"/"
)
(
is
(
=
"/"
(
public-settings/landing-page
)))
(
public-settings/landing-page!
"/one/two/three/"
)
(
is
(
=
"/one/two/three/"
(
public-settings/landing-page
)))
(
public-settings/landing-page!
"no-leading-slash"
)
(
is
(
=
"/no-leading-slash"
(
public-settings/landing-page
)))
(
public-settings/landing-page!
"/pathname?query=param#hash"
)
(
is
(
=
"/pathname?query=param#hash"
(
public-settings/landing-page
)))
(
public-settings/landing-page!
"#hash"
)
(
is
(
=
"/#hash"
(
public-settings/landing-page
)))
(
with-redefs
[
public-settings/site-url
(
constantly
"http://localhost"
)]
(
public-settings/landing-page!
"http://localhost/absolute/same-origin"
)
(
is
(
=
"/absolute/same-origin"
(
public-settings/landing-page
)))))
(
testing
"landing-page cannot be set to URLs with external origin"
(
is
(
thrown-with-msg?
Exception
#
"This field must be a relative URL."
(
public-settings/landing-page!
"https://google.com"
)))
(
is
(
thrown-with-msg?
Exception
#
"This field must be a relative URL."
(
public-settings/landing-page!
"sms://?&body=Hello"
)))
(
is
(
thrown-with-msg?
Exception
#
"This field must be a relative URL."
(
public-settings/landing-page!
"https://localhost/test"
)))
(
is
(
thrown-with-msg?
Exception
#
"This field must be a relative URL."
(
public-settings/landing-page!
"mailto:user@example.com"
)))
(
is
(
thrown-with-msg?
Exception
#
"This field must be a relative URL."
(
public-settings/landing-page!
"file:///path/to/resource"
)))))
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