Skip to content

Commit

Permalink
Improve Security on Form Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
badbreze committed Feb 15, 2024
1 parent 0027227 commit 9dccfc5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions framework/assets/yii.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ window.yii = (function ($) {
}
} else {
if (!isValidAction) {
action = pub.getCurrentUrl();
action = pub.getSafeUrl();
}
$form = $('<form/>', {method: method, action: action});
var target = $e.attr('target');
Expand Down Expand Up @@ -350,7 +350,16 @@ window.yii = (function ($) {
*/
getCurrentUrl: function () {
return window.location.href;
}
},

/**
* Returns the safest URL possiblebased on getCurrentUrl
* @returns {string}
*/
getSafeUrl: function () {
var url = this.getCurrentUrl();
return url.replace(/[^\d\w\&\?\=\[\]\/\:\.]*/gmi, "");
},
};

function initCsrfHandler() {
Expand Down

0 comments on commit 9dccfc5

Please sign in to comment.