Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checked for html characters in model #247

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions Views/dashboard_edit_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@
<script type="text/javascript" src="<?php echo $path; ?>Modules/feed/feed.js?ver=<?php echo $js_css_version; ?>"></script>

<?php require_once "Modules/dashboard/Views/loadwidgets.php"; ?>

<script>
// @see: Lib/misc/gettext.js
function getTranslations() {
return Object.assign({
"Saved": "<?php echo _("Saved") ?>",
"Could not save Dashboard": "<?php echo _("Could not save Dashboard") ?>",
"Items Saved": "<?php echo _("Items Saved") ?>"
}, LANG_JS);
}
</script>
<div id="dashboardpage">
<div id="widget_options" class="modal hide keyboard" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-header">
Expand Down Expand Up @@ -142,30 +151,29 @@ function toolboxMove(e) {

$("#save-dashboard").click(function (){
var currentcontent = $("#page").html();

var success = false;
if (currentcontent === lastsavecontent) {
// If it's not changed, just bypass actual saving and assume success
success = true;
showSuccess();
} else {
//recalculate the height so the page_height is shrunk to the minimum but still wrapping all components
//otherwise a user can drag a component far down then up again and a too high value will be stored to db.
designer.page_height = 0;
designer.scan();
designer.draw();
console.log("Dashboard HTML content: " + currentcontent);
var result=dashboard.setcontent(dashid,currentcontent,designer.page_height)
success = result.success;
}

if (success) {
$("#save-dashboard").attr('class','btn btn-success').text('<?php echo _("Saved") ?>');
$("#save-dashboard").attr("title","<?php echo _("Items Saved") ?>");
lastsavecontent = currentcontent;
} else {
alert('ERROR: Could not save Dashboard. '+result.message);

dashboard_v2.setcontent(dashid,currentcontent,designer.page_height)
.done(showSuccess)
.fail(showError)
}
});
function showError(xhr,status) {
throw(new Error(_("Could not save Dashboard. ") + status));
}
function showSuccess() {
$("#save-dashboard").attr("class","btn btn-success").text(_("Saved"));
$("#save-dashboard").attr("title",_("Items Saved"));
lastsavecontent = $("#page").html();
}

$(window).resize(function(){
designer.draw();
Expand Down
5 changes: 4 additions & 1 deletion dashboard_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@ public function set_content($userid, $id, $_content, $height)
require_once "$axdir/UTF8.php";
require_once "$axdir/AntiXSS.php";
$antiXss = new AntiXSS();
$nbsp_placeholder = "<!-- START-NON-BREAKING-SPACE --> <!-- END-NON-BREAKING-SPACE -->";
$_content = str_replace('&nbsp;',$nbsp_placeholder,$_content);
$content = htmlspecialchars_decode($antiXss->xss_clean($_content));
$_content = htmlspecialchars_decode($_content);
if ($content!=$_content) return array('success'=>false, 'message'=>'Error: Invalid dashboard content, content not saved');
} else {
$content = $_content;
}

// re-instate the &nbsp; character once all XSS tests are complete
$content = str_replace($nbsp_placeholder,'&nbsp;',$content);
$result = $this->mysqli->query("SELECT content FROM dashboard WHERE userid = '$userid' AND id='$id'");
$row = $result->fetch_object();
if ($row) {
Expand Down