Skip to content

Commit 2fcef55

Browse files
authored
Merge pull request #1828 from OpenC3/bug/sanitize-params-parent-dir
Disallow parent dir path in sanitize_params
2 parents 0f71247 + fc7e113 commit 2fcef55

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

openc3-cosmos-cmd-tlm-api/app/controllers/application_controller.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def authorization(permission, target_name: nil, perform_render: true)
5757
end
5858
end
5959

60-
def sanitize_params(param_list, require_params: true, allow_forward_slash: false)
60+
def sanitize_params(param_list, require_params: true, allow_forward_slash: false, allow_parent_dir: false)
6161
if require_params
6262
result = params.require(param_list)
6363
else
@@ -78,6 +78,9 @@ def sanitize_params(param_list, require_params: true, allow_forward_slash: false
7878
else
7979
value = arg.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�").strip.tr("\u{202E}%$|:;/\t\r\n\\", "-")
8080
end
81+
if not allow_parent_dir
82+
value = value.gsub(/(\.|%2e){2}/i, "-")
83+
end
8184
if value != arg
8285
render json: { status: 'error', message: "Invalid #{param_list[index]}: #{arg}" }, status: 400
8386
return false

openc3-cosmos-script-runner-api/app/controllers/application_controller.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def authorization(permission, target_name: nil)
6868
return true
6969
end
7070

71-
def sanitize_params(param_list, require_params: true, allow_forward_slash: false)
71+
def sanitize_params(param_list, require_params: true, allow_forward_slash: false, allow_parent_dir: false)
7272
if require_params
7373
result = params.require(param_list)
7474
else
@@ -89,6 +89,9 @@ def sanitize_params(param_list, require_params: true, allow_forward_slash: false
8989
else
9090
value = arg.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�").strip.tr("\u{202E}%$|:;/\t\r\n\\", "-")
9191
end
92+
if not allow_parent_dir
93+
value = value.gsub(/(\.|%2e){2}/i, "-")
94+
end
9295
if value != arg
9396
render json: { status: 'error', message: "Invalid #{param_list[index]}: #{arg}" }, status: 400
9497
return false

0 commit comments

Comments
 (0)