Skip to content

Commit

Permalink
Use angular's $sanitize to prevent XSS
Browse files Browse the repository at this point in the history
Addresses showdownjs#70 at least within angular.
  • Loading branch information
wkonkel committed Apr 22, 2015
1 parent eca8386 commit 2b2eb97
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ng-showdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (typeof angular !== 'undefined' && typeof Showdown !== 'undefined') {

module
.provider('$Showdown', provider)
.directive('sdModelToHtml', ['$Showdown', markdownToHtmlDirective])
.directive('sdModelToHtml', ['$Showdown', '$sanitize', markdownToHtmlDirective])
.filter('sdStripHtml', stripHtmlFilter);

/**
Expand Down Expand Up @@ -106,13 +106,13 @@ if (typeof angular !== 'undefined' && typeof Showdown !== 'undefined') {
* @param $Showdown
* @returns {*}
*/
function markdownToHtmlDirective($Showdown) {
function markdownToHtmlDirective($Showdown, $sanitize) {

var link = function (scope, element) {
scope.$watch('model', function (newValue) {
var val;
if (typeof newValue === 'string') {
val = $Showdown.makeHtml(newValue);
val = $sanitize($Showdown.makeHtml(newValue));
} else {
val = typeof newValue;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ if (typeof angular !== 'undefined' && typeof Showdown !== 'undefined') {
};
}

})(angular.module('Showdown', []), Showdown);
})(angular.module('Showdown', ['ngSanitize']), Showdown);

} else {

Expand Down

0 comments on commit 2b2eb97

Please sign in to comment.