Skip to content

Commit

Permalink
Handle incorrectly encoded tag keys
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Nov 7, 2024
1 parent e75ba66 commit 1e76290
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/changeset_tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def delete
end
begin
@key = Base64.urlsafe_decode64(params[:base64_key].to_s)
rescue ArgumentError
render :action => "invalid_tag", :status => :not_found
return
end
begin
@changeset_tag = ChangesetTag.find([params[:changeset_id], @key])
rescue ActiveRecord::RecordNotFound
render :action => "tag_not_found", :status => :not_found
Expand Down
7 changes: 7 additions & 0 deletions app/views/changeset_tags/invalid_tag.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% content_for :heading do %>
<h1><%= t(".heading") %></h1>
<% end %>

<div>
<p><%= t ".body" %>
</div>
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ en:
changeset_not_found:
heading: Changeset does not exist
body: "Sorry, changeset #%{id} could not be found."
invalid_tag:
heading: Invalid changeset tag
body: "Sorry, the requested tag key cannot be decoded."
tag_not_found:
heading: Changeset tag does not exist
body: "Sorry, tag %{key} could not be found in changeset #%{id}."
Expand Down
10 changes: 10 additions & 0 deletions test/controllers/changeset_tags_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ def test_delete_fail_no_changeset
assert_response :not_found
end

def test_delete_fail_invalid_key_encoding
changeset = create(:changeset)
moderator_user = create(:moderator_user)

session_for(moderator_user)

post delete_changeset_tags_path(changeset, :params => { :base64_key => "ZnJvbV9jb" })
assert_response :not_found
end

def test_delete_fail_no_key
changeset = create(:changeset)
moderator_user = create(:moderator_user)
Expand Down

0 comments on commit 1e76290

Please sign in to comment.