-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload files from a URL #3386
base: main
Are you sure you want to change the base?
Upload files from a URL #3386
Conversation
@@ -0,0 +1,21 @@ | |||
class UppyCompanionController < ApplicationController | |||
skip_forgery_protection |
Check failure
Code scanning / CodeQL
CSRF protection weakened or disabled High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 11 days ago
To fix the problem, we need to re-enable CSRF protection for the UppyCompanionController
by removing the skip_forgery_protection
call. This will ensure that all actions within the controller require a valid CSRF token, mitigating the risk of CSRF attacks.
- Remove the
skip_forgery_protection
call on line 2. - Ensure that the
protect_from_forgery
method is used with thewith: :exception
option to raise an exception on an invalid CSRF token.
-
Copy modified line R2
@@ -1,3 +1,3 @@ | ||
class UppyCompanionController < ApplicationController | ||
skip_forgery_protection | ||
protect_from_forgery with: :exception | ||
|
def url_meta | ||
authorize :model, :new? | ||
# Do HEAD request for url | ||
response = Faraday.head params[:url] |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 11 days ago
To fix the problem, we need to ensure that the user-provided URL is validated against a list of authorized URLs or restricted to a particular host or URL prefix. This can be achieved by maintaining a list of allowed hosts and checking if the user-provided URL belongs to one of these hosts before making the request.
- Create a list of allowed hosts.
- Parse the user-provided URL and check if its host is in the list of allowed hosts.
- If the host is not allowed, return an error response.
- If the host is allowed, proceed with the request.
-
Copy modified lines R1-R2 -
Copy modified lines R8-R21 -
Copy modified lines R26-R33
@@ -1 +1,3 @@ | ||
require 'uri' | ||
|
||
class UppyCompanionController < ApplicationController | ||
@@ -5,10 +7,16 @@ | ||
authorize :model, :new? | ||
# Do HEAD request for url | ||
response = Faraday.head params[:url] | ||
render json: { | ||
name: response.headers["filename"], | ||
type: response.headers["content-type"], | ||
size: response.headers["content-length"], | ||
status_code: response.status | ||
} | ||
url = params[:url] | ||
uri = URI.parse(url) | ||
if ALLOWED_HOSTS.include?(uri.host) | ||
# Do HEAD request for url | ||
response = Faraday.head url | ||
render json: { | ||
name: response.headers["filename"], | ||
type: response.headers["content-type"], | ||
size: response.headers["content-length"], | ||
status_code: response.status | ||
} | ||
else | ||
render status: :bad_request, json: { error: "Invalid URL" } | ||
end | ||
end | ||
@@ -17,4 +25,10 @@ | ||
authorize :model, :new? | ||
Faraday.get params[:url] | ||
render status: :internal_server_error, json: {} | ||
url = params[:url] | ||
uri = URI.parse(url) | ||
if ALLOWED_HOSTS.include?(uri.host) | ||
Faraday.get url | ||
render status: :ok, json: {} | ||
else | ||
render status: :bad_request, json: { error: "Invalid URL" } | ||
end | ||
end |
|
||
def url_get | ||
authorize :model, :new? | ||
Faraday.get params[:url] |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 11 days ago
To fix the problem, we need to ensure that the user-provided URL is validated against a list of authorized URLs or restricted to a particular host or URL prefix. This can be achieved by maintaining a list of allowed domains and checking if the user-provided URL belongs to one of these domains before making the request.
We will:
- Define a list of allowed domains.
- Parse the user-provided URL and check if its host is in the list of allowed domains.
- Only proceed with the request if the URL is valid.
-
Copy modified lines R1-R2 -
Copy modified lines R8-R21 -
Copy modified lines R26-R33
@@ -1 +1,3 @@ | ||
require 'uri' | ||
|
||
class UppyCompanionController < ApplicationController | ||
@@ -5,10 +7,16 @@ | ||
authorize :model, :new? | ||
# Do HEAD request for url | ||
response = Faraday.head params[:url] | ||
render json: { | ||
name: response.headers["filename"], | ||
type: response.headers["content-type"], | ||
size: response.headers["content-length"], | ||
status_code: response.status | ||
} | ||
url = params[:url] | ||
uri = URI.parse(url) | ||
if ALLOWED_DOMAINS.include?(uri.host) | ||
# Do HEAD request for url | ||
response = Faraday.head url | ||
render json: { | ||
name: response.headers["filename"], | ||
type: response.headers["content-type"], | ||
size: response.headers["content-length"], | ||
status_code: response.status | ||
} | ||
else | ||
render status: :bad_request, json: { error: "Invalid URL" } | ||
end | ||
end | ||
@@ -17,4 +25,10 @@ | ||
authorize :model, :new? | ||
Faraday.get params[:url] | ||
render status: :internal_server_error, json: {} | ||
url = params[:url] | ||
uri = URI.parse(url) | ||
if ALLOWED_DOMAINS.include?(uri.host) | ||
Faraday.get url | ||
render status: :ok, json: {} | ||
else | ||
render status: :bad_request, json: { error: "Invalid URL" } | ||
end | ||
end |
WIP to resolve #2376
Implements the
url_meta
Uppy companion API, but still needs theurl_get
. See #2376 for background.