-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edit: Sanitization of Markdown content
- Loading branch information
Showing
2 changed files
with
30 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
// Modules | ||
// var validator = require('validator'); | ||
|
||
// Sanitize Content | ||
// This will disallow <script> and <style> embeds | ||
// because output will be HTML-encoded. | ||
// If you need images, links, etc. use the Markdown format (see docs) | ||
// | ||
// This was the prior content sanitizer, which was too aggressive | ||
// Markdown characters got encoded/escaped to the point of being unusable | ||
// return validator.escape(str); | ||
// | ||
// Instead we now will remove problematic characters not in the Markdown spec | ||
// https://www.markdownguide.org/cheat-sheet/ | ||
// Includes: >, & | ||
// More may be added in the future | ||
// Additionally, Content Security Policy when implemented will help | ||
|
||
// TODO: Add Test | ||
function sanitize_markdown(str) { | ||
return str | ||
.replace(/</g, '<') | ||
.replace(/(\s)&(\s)/g, ' & '); | ||
} | ||
|
||
// Exports | ||
module.exports = exports = sanitize_markdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters