Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
normandy
pleroma
Commits
bdc8112e
Verified
Commit
bdc8112e
authored
6 years ago
by
href
Browse files
Options
Downloads
Patches
Plain Diff
Media proxy: fix url encoding
parent
7d86c0c5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/pleroma/web/media_proxy/controller.ex
+6
-1
6 additions, 1 deletion
lib/pleroma/web/media_proxy/controller.ex
lib/pleroma/web/media_proxy/media_proxy.ex
+8
-1
8 additions, 1 deletion
lib/pleroma/web/media_proxy/media_proxy.ex
test/media_proxy_test.exs
+37
-0
37 additions, 0 deletions
test/media_proxy_test.exs
with
51 additions
and
2 deletions
lib/pleroma/web/media_proxy/controller.ex
+
6
−
1
View file @
bdc8112e
...
...
@@ -24,7 +24,12 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
end
def
filename_matches
(
has_filename
,
path
,
url
)
do
filename
=
MediaProxy
.
filename
(
url
)
filename
=
url
|>
MediaProxy
.
filename
()
|>
URI
.
decode
()
path
=
URI
.
decode
(
path
)
cond
do
has_filename
&&
filename
&&
Path
.
basename
(
path
)
!=
filename
->
{
:wrong_filename
,
filename
}
...
...
This diff is collapsed.
Click to expand it.
lib/pleroma/web/media_proxy/media_proxy.ex
+
8
−
1
View file @
bdc8112e
...
...
@@ -14,7 +14,14 @@ defmodule Pleroma.Web.MediaProxy do
url
else
secret
=
Application
.
get_env
(
:pleroma
,
Pleroma
.
Web
.
Endpoint
)[
:secret_key_base
]
base64
=
Base
.
url_encode64
(
url
,
@base64_opts
)
# The URL is url-decoded and encoded again to ensure it is correctly encoded and not twice.
base64
=
url
|>
URI
.
decode
()
|>
URI
.
encode
()
|>
Base
.
url_encode64
(
@base64_opts
)
sig
=
:crypto
.
hmac
(
:sha
,
secret
,
base64
)
sig64
=
sig
|>
Base
.
url_encode64
(
@base64_opts
)
...
...
This diff is collapsed.
Click to expand it.
test/media_proxy_test.exs
+
37
−
0
View file @
bdc8112e
defmodule
Pleroma
.
MediaProxyTest
do
use
ExUnit
.
Case
import
Pleroma
.
Web
.
MediaProxy
alias
Pleroma
.
Web
.
MediaProxy
.
MediaProxyController
describe
"when enabled"
do
setup
do
...
...
@@ -65,6 +66,14 @@ defmodule Pleroma.MediaProxyTest do
assert
decode_result
(
encoded
)
==
url
end
test
"ensures urls are url-encoded"
do
assert
decode_result
(
url
(
"https://pleroma.social/Hello world.jpg"
))
==
"https://pleroma.social/Hello%20world.jpg"
assert
decode_result
(
url
(
"https://pleroma.social/Hello%20world.jpg"
))
==
"https://pleroma.social/Hello%20world.jpg"
end
test
"validates signature"
do
secret_key_base
=
Pleroma
.
Config
.
get
([
Pleroma
.
Web
.
Endpoint
,
:secret_key_base
])
...
...
@@ -83,6 +92,34 @@ defmodule Pleroma.MediaProxyTest do
assert
decode_url
(
sig
,
base64
)
==
{
:error
,
:invalid_signature
}
end
test
"filename_matches matches url encoded paths"
do
assert
MediaProxyController
.
filename_matches
(
true
,
"/Hello%20world.jpg"
,
"http://pleroma.social/Hello world.jpg"
)
==
:ok
assert
MediaProxyController
.
filename_matches
(
true
,
"/Hello%20world.jpg"
,
"http://pleroma.social/Hello%20world.jpg"
)
==
:ok
end
test
"filename_matches matches non-url encoded paths"
do
assert
MediaProxyController
.
filename_matches
(
true
,
"/Hello world.jpg"
,
"http://pleroma.social/Hello%20world.jpg"
)
==
:ok
assert
MediaProxyController
.
filename_matches
(
true
,
"/Hello world.jpg"
,
"http://pleroma.social/Hello world.jpg"
)
==
:ok
end
test
"uses the configured base_url"
do
base_url
=
Pleroma
.
Config
.
get
([
:media_proxy
,
:base_url
])
...
...
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