Commit cacd7415 authored by Felipe Artur Cardozo's avatar Felipe Artur Cardozo

Merge branch 'security-fj-missing-csrf-system-hooks-ee' into 'master'

[master] Missing CSRF in System Hooks

See merge request gitlab/gitlab-ee!647
parents 1ffa979b ff99ac2c
...@@ -10,7 +10,7 @@ module HooksHelper ...@@ -10,7 +10,7 @@ module HooksHelper
trigger_human_name = trigger.to_s.tr('_', ' ').camelize trigger_human_name = trigger.to_s.tr('_', ' ').camelize
link_to path, rel: 'nofollow' do link_to path, rel: 'nofollow', method: :post do
content_tag(:span, trigger_human_name) content_tag(:span, trigger_human_name)
end end
end end
......
---
title: Adding CSRF protection to Hooks test action
merge_request:
author:
type: security
...@@ -60,7 +60,7 @@ namespace :admin do ...@@ -60,7 +60,7 @@ namespace :admin do
resources :hooks, only: [:index, :create, :edit, :update, :destroy] do resources :hooks, only: [:index, :create, :edit, :update, :destroy] do
member do member do
get :test post :test
end end
resources :hook_logs, only: [:show] do resources :hook_logs, only: [:show] do
......
...@@ -83,7 +83,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do ...@@ -83,7 +83,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do
member do member do
get :test post :test
end end
end end
......
...@@ -337,7 +337,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -337,7 +337,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
resources :hooks, only: [:index, :create, :edit, :update, :destroy], constraints: { id: /\d+/ } do resources :hooks, only: [:index, :create, :edit, :update, :destroy], constraints: { id: /\d+/ } do
member do member do
get :test post :test
end end
resources :hook_logs, only: [:show] do resources :hook_logs, only: [:show] do
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
.col-md-4.col-lg-5.text-right-lg.prepend-top-5 .col-md-4.col-lg-5.text-right-lg.prepend-top-5
%span.append-right-10.inline %span.append-right-10.inline
SSL Verification: #{hook.enable_ssl_verification ? "enabled" : "disabled"} SSL Verification: #{hook.enable_ssl_verification ? "enabled" : "disabled"}
= link_to "Test", test_group_hook_path(@group, hook), class: "btn btn-sm" = link_to "Test", test_group_hook_path(@group, hook), class: "btn btn-sm", method: :post
= link_to group_hook_path(@group, hook), data: { confirm: 'Are you sure?'}, method: :delete, class: "btn btn-transparent" do = link_to group_hook_path(@group, hook), data: { confirm: 'Are you sure?'}, method: :delete, class: "btn btn-transparent" do
%span.sr-only Remove %span.sr-only Remove
= icon('trash') = icon('trash')
require "spec_helper" require "rails_helper"
describe "User tests hooks" do describe "User tests hooks", :js do
set(:group) { create(:group) } let!(:group) { create(:group) }
set(:hook) { create(:group_hook, group: group) } let!(:hook) { create(:group_hook, group: group) }
set(:user) { create(:user) } let!(:user) { create(:user) }
before do before do
group.add_owner(user) group.add_owner(user)
......
...@@ -7,7 +7,7 @@ describe "routes to the proper webhooks controller", type: :routing do ...@@ -7,7 +7,7 @@ describe "routes to the proper webhooks controller", type: :routing do
it "routes the test action" do it "routes the test action" do
expect( expect(
get: polymorphic_path([project.namespace.becomes(Namespace), project, project_hook], action: :test) post: polymorphic_path([project.namespace.becomes(Namespace), project, project_hook], action: :test)
).to route_to(controller: 'projects/hooks', ).to route_to(controller: 'projects/hooks',
action: 'test', action: 'test',
namespace_id: project.namespace.name, namespace_id: project.namespace.name,
...@@ -32,7 +32,7 @@ describe "routes to the proper webhooks controller", type: :routing do ...@@ -32,7 +32,7 @@ describe "routes to the proper webhooks controller", type: :routing do
it "routes the test action" do it "routes the test action" do
expect( expect(
get: polymorphic_path([group, group_hook], action: :test) post: polymorphic_path([group, group_hook], action: :test)
).to route_to(controller: 'groups/hooks', ).to route_to(controller: 'groups/hooks',
action: 'test', action: 'test',
group_id: group.name, group_id: group.name,
......
...@@ -79,7 +79,7 @@ end ...@@ -79,7 +79,7 @@ end
# edit_admin_hook GET /admin/hooks/:id(.:format) admin/hooks#edit # edit_admin_hook GET /admin/hooks/:id(.:format) admin/hooks#edit
describe Admin::HooksController, "routing" do describe Admin::HooksController, "routing" do
it "to #test" do it "to #test" do
expect(get("/admin/hooks/1/test")).to route_to('admin/hooks#test', id: '1') expect(post("/admin/hooks/1/test")).to route_to('admin/hooks#test', id: '1')
end end
it "to #index" do it "to #index" do
......
...@@ -389,7 +389,7 @@ describe 'project routing' do ...@@ -389,7 +389,7 @@ describe 'project routing' do
# DELETE /:project_id/hooks/:id(.:format) hooks#destroy # DELETE /:project_id/hooks/:id(.:format) hooks#destroy
describe Projects::HooksController, 'routing' do describe Projects::HooksController, 'routing' do
it 'to #test' do it 'to #test' do
expect(get('/gitlab/gitlabhq/hooks/1/test')).to route_to('projects/hooks#test', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') expect(post('/gitlab/gitlabhq/hooks/1/test')).to route_to('projects/hooks#test', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1')
end end
it_behaves_like 'RESTful project resources' do it_behaves_like 'RESTful project resources' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment