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

Security Fix - XSS on several page where course list bind. #542

Merged
merged 2 commits into from
Aug 28, 2023
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 assets/react/front/_select_dd_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ window.selectSearchField = (selectElement) => {
Array.from(options).forEach((item) => {
optionsList += `
<div class="tutor-form-select-option">
<span tutor-dropdown-item data-key="${item.value}" class="tutor-nowrap-ellipsis" title="${item.text}">${item.text}</span>
<span tutor-dropdown-item data-key="${item.value}" class="tutor-nowrap-ellipsis" title="${tutor_esc_html(item.text)}">${tutor_esc_html(item.text)}</span>
</div>
`;
});
Expand Down
22 changes: 22 additions & 0 deletions assets/react/lib/tutor.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,28 @@ window.tutor_toast = function( title, description, type, autoClose = true ) {
}
};

/**
* Escape HTML and return safe HTML
*
* @since 2.2.4
*
* @param {string} unsafeText HTML string
* @returns string
*/
window.tutor_esc_html = function (unsafeText) {
let safeHTML = ''
let div = document.createElement('div');
/**
* When set an HTML string to an element's innerText
* the browser automatically escapes any HTML tags and
* treats the content as plain text.
*/
div.innerText = unsafeText;
safeHTML = div.innerHTML;
div.remove()

return safeHTML;
}

// enable custom selector when modal opens
window.addEventListener('tutor_modal_shown', (e) => {
Expand Down
Loading