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

Sanitize feature name #15

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rollout/ui/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,9 @@ def feature_to_hash(feature)
percentage: feature.percentage
}
end

def sanitized_name(feature_name)
Rack::Utils.escape_html(feature_name)
end
end
end
6 changes: 3 additions & 3 deletions lib/rollout/ui/views/features/index.slim
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ h2.font-semibold.text-xl.text-gray-500.pt-12.flex.items-center
= time_ago(@rollout.logging.updated_at(feature_name))
td.flex.items-center.py-2.justify-end.whitespace-no-wrap.pl-3
form action=activate_percentage_feature_path(feature_name, 100) method='POST'
button.p-3.bg-gray-100.ml-1.rounded-sm.font-bold.leading-none.transition-colors.duration-150(class='hover:bg-gray-200' type='submit' onclick="return confirm('Are you sure you want activate #{feature_name} to 100%?')")
button.p-3.bg-gray-100.ml-1.rounded-sm.font-bold.leading-none.transition-colors.duration-150(class='hover:bg-gray-200' type='submit' onclick="return confirm('Are you sure you want activate #{sanitized_name(feature_name)} to 100%?')")
' 100%
form action=activate_percentage_feature_path(feature_name, 0) method='POST'
button.p-3.bg-gray-100.ml-1.rounded-sm.font-bold.leading-none.transition-colors.duration-150(class='hover:bg-gray-200' type='submit' onclick="return confirm('Are you sure you want activate #{feature_name} to 0%?')")
button.p-3.bg-gray-100.ml-1.rounded-sm.font-bold.leading-none.transition-colors.duration-150(class='hover:bg-gray-200' type='submit' onclick="return confirm('Are you sure you want activate #{sanitized_name(feature_name)} to 0%?')")
' 0%
form action=delete_feature_path(feature_name) method='POST'
button.p-3.bg-gray-100.ml-1.rounded-sm.font-bold.leading-none.transition-colors.duration-150(class='hover:bg-gray-200' type='submit' onclick="return confirm('Are you sure you want to delete #{feature_name}?')")
button.p-3.bg-gray-100.ml-1.rounded-sm.font-bold.leading-none.transition-colors.duration-150(class='hover:bg-gray-200' type='submit' onclick="return confirm('Are you sure you want to delete #{sanitized_name(feature_name)}?')")
' Delete

- global_history_events = @rollout.respond_to?(:logging) ? @rollout.logging.global_events.reverse : []
Expand Down
2 changes: 1 addition & 1 deletion lib/rollout/ui/views/features/show.slim
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ main.p-6.bg-gray-100.max-w-lg.w-full.text-sm.rounded-sm

.flex.items-center.justify-end
form action=delete_feature_path(@feature.name) method='POST'
button.mr-5.text-gray-600(class='hover:underline' type='submit' onclick="return confirm('Are you sure you want to delete #{@feature.name}?')")
button.mr-5.text-gray-600(class='hover:underline' type='submit' onclick="return confirm('Are you sure you want to delete #{sanitized_name(@feature.name)}?')")
| Delete
button.py-4.px-5.bg-gray-700.text-gray-200.rounded-sm.font-bold.leading-none.transition-colors.duration-200(
type='submit'
Expand Down
22 changes: 19 additions & 3 deletions spec/rollout/ui/web_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,35 @@ def app
ROLLOUT.delete(:fake_test_feature_for_rollout_ui_webspec)
end

it "rescapes javascript in the action index" do
ROLLOUT.activate(:'+alert(1)+')

get '/'

expect(last_response).to be_ok
expect(last_response.body).to include('Rollout UI') & include("'+alert(1)+'")
end

it "renders show html" do
get '/features/test'

expect(last_response).to be_ok
expect(last_response.body).to include('Rollout UI') & include('test')
end

it "escapes javascript in the action show" do
get "/features/'+alert(1)+'"

expect(last_response).to be_ok
expect(last_response.body).to include('Rollout UI') & include("'+alert(1)+'")
end

it "renders show json" do
ROLLOUT.activate(:fake_test_feature_for_rollout_ui_webspec)
header 'Accept', 'application/json'

get '/features/fake_test_feature_for_rollout_ui_webspec'

expect(last_response).to be_ok
expect(last_response.headers).to include('Content-Type' => 'application/json')
response = JSON.parse(last_response.body)
Expand All @@ -98,4 +114,4 @@ def app

ROLLOUT.delete(:fake_test_feature_for_rollout_ui_webspec)
end
end
end