Skip to content

Commit 801df4d

Browse files
authored
Merge pull request #15 from shennyg/fix/escape-entities-craft4
Escape HTML entities in log files for Craft 4
2 parents b9c8575 + 8db7a69 commit 801df4d

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 4.0.1 - 2024-03-19
2+
### Fixed
3+
- Escape unsafe HTML, this allows XML and HTML tags to display as text instead of render
4+
5+
## 3.0.6 - 2022-05-10
6+
### Fixed
7+
- Escape unsafe HTML, this allows XML and HTML tags to display as text instead of render
8+
19
## 4.0.0 - 2022-07-11
210
### Changed
311
- Craft 4 release

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "ether/logs",
33
"description": "Access logs from the CP",
4+
"version": "4.0.1",
45
"type": "craft-plugin",
56
"minimum-stability": "dev",
67
"require": {

src/Utility.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,43 @@ function ($var) {
6363
CSS;
6464

6565
$js = <<<JS
66+
/** Mixin to extend the String type with a method to escape unsafe characters
67+
* for use in HTML. Uses OWASP guidelines for safe strings in HTML.
68+
*
69+
* Credit: http://benv.ca/2012/10/4/you-are-probably-misusing-DOM-text-methods/
70+
* https://github.com/janl/mustache.js/blob/16ffa430a111dc293cd9ed899ecf9da3729f58bd/mustache.js#L62
71+
*
72+
* Maintained by [email protected]
73+
*
74+
* @license http://opensource.org/licenses/MIT
75+
*
76+
* @version 1.0
77+
*
78+
* @mixin
79+
*/
80+
(function(){
81+
"use strict";
82+
83+
function escapeHtml() {
84+
return this.replace(/[&<>"'\/]/g, function (s) {
85+
var entityMap = {
86+
"&": "&amp;",
87+
"<": "&lt;",
88+
">": "&gt;",
89+
'"': '&quot;',
90+
"'": '&#39;',
91+
"/": '&#x2F;'
92+
};
93+
94+
return entityMap[s];
95+
});
96+
}
97+
98+
if (typeof(String.prototype.escapeHtml) !== 'function') {
99+
String.prototype.escapeHtml = escapeHtml;
100+
}
101+
})();
102+
66103
const logElem = document.getElementById("__log");
67104
68105
function streamLog (log) {
@@ -75,7 +112,7 @@ function streamLog (log) {
75112
}).then(data => data.text()).then(data => {
76113
let html = "";
77114
78-
data.split("\\n").forEach(line => {
115+
data.escapeHtml().split("\\n").forEach(line => {
79116
let m = /^(\d{4}(-\d{2}){2} (\d{2}:){2}\d{2}) (\[[^\]]+\]){3}\[([^\]]+)\]\[([^\]]+)\]/i.exec(line);
80117
if (m !== null) {
81118
let colour = "";

0 commit comments

Comments
 (0)