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

TW21240098, cleaning comments with script tags #165

Merged
merged 3 commits into from
Feb 17, 2025
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
2 changes: 1 addition & 1 deletion classes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function save() {
global $DB, $USER;

$this->timemodified = time();
$this->content = html_to_text($this->content, 5000, false);
$this->content = clean_param(html_to_text($this->content, 5000, false), PARAM_TEXT);

if ($this->id > 0) {
$DB->update_record('board_comments', $this);
Expand Down
11 changes: 11 additions & 0 deletions classes/tables/comments_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ public function other_cols($colname, $value) {
}
}

/**
* Format each row of returned data.
*
* @param array|object $row row of data from db used to make one row of the table.
* @return array one row for the table with sanitised content.
*/
public function format_row($row): array {
$row->content = clean_param($row->content, PARAM_TEXT);
return parent::format_row($row);
}

/**
* Displays the table.
*/
Expand Down
2 changes: 1 addition & 1 deletion external.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ public static function get_comments($noteid) {
$comment = (object)[];
$comment->id = $note->id;
$comment->noteid = $note->noteid;
$comment->content = $note->content;
$comment->content = clean_param($note->content, PARAM_TEXT);
$comment->candelete = (($canpost && $note->userid === $USER->id) || $candeleteall) ? true : false;
$comment->date = userdate($note->timecreated);
$comments[] = $comment;
Expand Down