Skip to content

Commit

Permalink
Fix missing authentication (CSRF) when using related issues block (#90
Browse files Browse the repository at this point in the history
…and PR #93)
  • Loading branch information
Ilogeek committed Apr 23, 2022
1 parent 750e602 commit dac2c85
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion assets/javascripts/issue_dynamic_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ if (_CONF_DISPLAY_EDIT_ICON === "block"){
$('body.controller-issues.action-show .issue.details').addClass('showPencils');
}

let updateCSRFToken = function(token){
document.querySelectorAll('input[name="authenticity_token"]').forEach(elt => elt.value = token);
document.querySelector('meta[name="csrf-token"]').setAttribute("content", token);
}

let setCSRFTokenInput = function(token){
document.querySelectorAll('form[method="post"]').forEach(elt => {
if(!elt.querySelectorAll('input[name="authenticity_token"]').length){
let input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", "authenticity_token");
input.value = token;
elt.insertBefore(input, null);
}
});
}

/* Generate edit block */
var getEditFormHTML = function(attribute){
var formElement = $('#issue_' + attribute + "_id");
Expand Down Expand Up @@ -317,6 +334,8 @@ var sendData = function(serialized_data){
$('body').find('input[type=date]').datepickerFallback(datepickerOptions);
}

setCSRFTokenInput($(parsed).find('input[name="authenticity_token"]').val());
updateCSRFToken($(parsed).find('input[name="authenticity_token"]').val());
setCheckVersionInterval(true);
},
error: function(xhr, msg, error) {
Expand Down Expand Up @@ -354,4 +373,5 @@ var sendData = function(serialized_data){
}

// Init plugin
cloneEditForm();
cloneEditForm();
setCSRFTokenInput(document.querySelector('meta[name="csrf-token"]').getAttribute("content"));
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'redmine'

require 'details_issue_hooks'
require_relative './lib/details_issue_hooks.rb'

Redmine::Plugin.register :redmine_issue_dynamic_edit do
name 'Redmine Dynamic edit Issue plugin'
Expand Down

0 comments on commit dac2c85

Please sign in to comment.