Skip to content

Commit 0dad4c5

Browse files
committed
ui(admin): better handling of manual HTML rendering
1 parent b1fa392 commit 0dad4c5

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

public/themes/pterodactyl/js/admin/new-server.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ $('#pEggId').on('change', function (event) {
109109
),
110110
});
111111

112+
function escapeHtml(str) {
113+
var div = document.createElement('div');
114+
div.appendChild(document.createTextNode(str));
115+
return div.innerHTML;
116+
}
117+
112118
const variableIds = {};
113119
$('#appendVariablesTo').html('');
114120
$.each(_.get(objectChain, 'variables', []), function (i, item) {
@@ -117,11 +123,11 @@ $('#pEggId').on('change', function (event) {
117123
let isRequired = (item.required === 1) ? '<span class="label label-danger">Required</span> ' : '';
118124
let dataAppend = ' \
119125
<div class="form-group col-sm-6"> \
120-
<label for="var_ref_' + item.id + '" class="control-label">' + isRequired + item.name + '</label> \
121-
<input type="text" id="var_ref_' + item.id + '" autocomplete="off" name="environment[' + item.env_variable + ']" class="form-control" value="' + item.default_value + '" /> \
122-
<p class="text-muted small">' + item.description + '<br /> \
123-
<strong>Access in Startup:</strong> <code>{{' + item.env_variable + '}}</code><br /> \
124-
<strong>Validation Rules:</strong> <code>' + item.rules + '</code></small></p> \
126+
<label for="var_ref_' + escapeHtml(item.id) + '" class="control-label">' + isRequired + escapeHtml(item.name) + '</label> \
127+
<input type="text" id="var_ref_' + escapeHtml(item.id) + '" autocomplete="off" name="environment[' + escapeHtml(item.env_variable) + ']" class="form-control" value="' + escapeHtml(item.default_value) + '" /> \
128+
<p class="text-muted small">' + escapeHtml(item.description) + '<br /> \
129+
<strong>Access in Startup:</strong> <code>{{' + escapeHtml(item.env_variable) + '}}</code><br /> \
130+
<strong>Validation Rules:</strong> <code>' + escapeHtml(item.rules) + '</code></small></p> \
125131
</div> \
126132
';
127133
$('#appendVariablesTo').append(dataAppend);

resources/views/admin/nodes/view/index.blade.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,20 @@
145145
@section('footer-scripts')
146146
@parent
147147
<script>
148+
function escapeHtml(str) {
149+
var div = document.createElement('div');
150+
div.appendChild(document.createTextNode(str));
151+
return div.innerHTML;
152+
}
153+
148154
(function getInformation() {
149155
$.ajax({
150156
method: 'GET',
151157
url: '/admin/nodes/view/{{ $node->id }}/system-information',
152158
timeout: 5000,
153159
}).done(function (data) {
154-
$('[data-attr="info-version"]').html(data.version);
155-
$('[data-attr="info-system"]').html(data.system.type + ' (' + data.system.arch + ') <code>' + data.system.release + '</code>');
160+
$('[data-attr="info-version"]').html(escapeHtml(data.version));
161+
$('[data-attr="info-system"]').html(escapeHtml(data.system.type) + ' (' + escapeHtml(data.system.arch) + ') <code>' + escapeHtml(data.system.release) + '</code>');
156162
$('[data-attr="info-cpus"]').html(data.system.cpus);
157163
}).fail(function (jqXHR) {
158164

resources/views/admin/servers/view/startup.blade.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@
107107
@parent
108108
{!! Theme::js('vendor/lodash/lodash.js') !!}
109109
<script>
110+
function escapeHtml(str) {
111+
var div = document.createElement('div');
112+
div.appendChild(document.createTextNode(str));
113+
return div.innerHTML;
114+
}
115+
110116
$(document).ready(function () {
111117
$('#pEggId').select2({placeholder: 'Select a Nest Egg'}).on('change', function () {
112118
var selectedEgg = _.isNull($(this).val()) ? $(this).find('option').first().val() : $(this).val();
@@ -149,15 +155,15 @@
149155
<div class="col-xs-12"> \
150156
<div class="box"> \
151157
<div class="box-header with-border"> \
152-
<h3 class="box-title">' + isRequired + item.name + '</h3> \
158+
<h3 class="box-title">' + isRequired + escapeHtml(item.name) + '</h3> \
153159
</div> \
154160
<div class="box-body"> \
155-
<input name="environment[' + item.env_variable + ']" class="form-control" type="text" id="egg_variable_' + item.env_variable + '" /> \
156-
<p class="no-margin small text-muted">' + item.description + '</p> \
161+
<input name="environment[' + escapeHtml(item.env_variable) + ']" class="form-control" type="text" id="egg_variable_' + escapeHtml(item.env_variable) + '" /> \
162+
<p class="no-margin small text-muted">' + escapeHtml(item.description) + '</p> \
157163
</div> \
158164
<div class="box-footer"> \
159-
<p class="no-margin text-muted small"><strong>Startup Command Variable:</strong> <code>' + item.env_variable + '</code></p> \
160-
<p class="no-margin text-muted small"><strong>Input Rules:</strong> <code>' + item.rules + '</code></p> \
165+
<p class="no-margin text-muted small"><strong>Startup Command Variable:</strong> <code>' + escapeHtml(item.env_variable) + '</code></p> \
166+
<p class="no-margin text-muted small"><strong>Input Rules:</strong> <code>' + escapeHtml(item.rules) + '</code></p> \
161167
</div> \
162168
</div> \
163169
</div>';

0 commit comments

Comments
 (0)