Skip to content
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

Updated NeLS Integration #2167

Draft
wants to merge 170 commits into
base: main
Choose a base branch
from
Draft

Updated NeLS Integration #2167

wants to merge 170 commits into from

Conversation

stuzart
Copy link
Member

@stuzart stuzart commented Mar 12, 2025

No description provided.

aapaolaza and others added 30 commits December 13, 2021 10:47
Waiting on create dataset, upload metadata API support
waiting for info before finishing off
@stuzart stuzart added this to the 1.17.0 milestone Mar 12, 2025
@stuzart stuzart marked this pull request as draft March 12, 2025 11:30
raise Nels::Rest::Client::FetchFileError, 'temp copy of file doesnt exist' unless File.exist?(path)

# send_data blocks and allows the file to be cleaned up afterwards
File.open(path, 'r') do |f|

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

Copilot Autofix AI 11 days ago

To fix the problem, we need to ensure that the key parameter is properly validated and sanitized to prevent any form of path manipulation. We can achieve this by using a whitelist approach to only allow known good patterns for the key parameter. Additionally, we should ensure that the path is constructed in a way that prevents directory traversal attacks.

The best way to fix the problem is to:

  1. Validate the key parameter using a strict whitelist of allowed characters.
  2. Ensure that the path is constructed in a secure manner that prevents directory traversal.
Suggested changeset 1
app/controllers/nels_controller.rb

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app/controllers/nels_controller.rb b/app/controllers/nels_controller.rb
--- a/app/controllers/nels_controller.rb
+++ b/app/controllers/nels_controller.rb
@@ -147,8 +147,7 @@
 
-    unless key =~ /^[0-9a-z-]+$/
+    unless key =~ /\A[0-9a-z-]+\z/
       raise Nels::Rest::Client::FetchFileError, 'Invalid file key'
     end
-    sanitized_key = key.gsub(/[^0-9a-z-]/, '')
-    path = File.join("/tmp", "nels-download-#{sanitized_key}")
-    raise Nels::Rest::Client::FetchFileError, 'temp copy of file doesnt exist' unless File.exist?(path)
+    path = File.join("/tmp", "nels-download-#{key}")
+    raise Nels::Rest::Client::FetchFileError, 'temp copy of file doesnt exist' unless File.exist?(path) && path.start_with?("/tmp/nels-download-")
 
EOF
@@ -147,8 +147,7 @@

unless key =~ /^[0-9a-z-]+$/
unless key =~ /\A[0-9a-z-]+\z/
raise Nels::Rest::Client::FetchFileError, 'Invalid file key'
end
sanitized_key = key.gsub(/[^0-9a-z-]/, '')
path = File.join("/tmp", "nels-download-#{sanitized_key}")
raise Nels::Rest::Client::FetchFileError, 'temp copy of file doesnt exist' unless File.exist?(path)
path = File.join("/tmp", "nels-download-#{key}")
raise Nels::Rest::Client::FetchFileError, 'temp copy of file doesnt exist' unless File.exist?(path) && path.start_with?("/tmp/nels-download-")

Copilot is powered by AI and may make mistakes. Always verify output.
@stuzart stuzart committed this autofix suggestion 11 days ago.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants