fix: improve sanitation of toasts that bypass HTML escaping (#5540) * fix: improve sanitation of toasts that bypass HTML escaping * fix: replace absolute lib.js import with relative Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

2e4ca3dabf6503451587f1c28387e742e08ea60c

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
5 files changed, +18 -14Ignore whitespace
public/scripts/action-loader-slashcommands.js+3 -2
@@ -7,6 +7,7 @@ import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCom
77import { SlashCommandEnumValue, enumTypes } from './slash-commands/SlashCommandEnumValue.js';
88import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
99import { isFalseBoolean } from './utils.js';
10+import { DOMPurify } from '../lib.js';
1011
1112/**
1213 * Registers slash commands for the action loader module.
@@ -275,8 +276,8 @@ export function registerActionLoaderSlashCommands() {
275276 slug: typeof args.slug === 'string' ? String(args.slug) : 'slash-show',
276277 blocking,
277278 toastMode,
278- message,
279+ message: DOMPurify.sanitize(message),
279- title,
280+ title: DOMPurify.sanitize(title),
280281 stopTooltip,
281282 onStop: createClosureHandler(args.onStop),
282283 onHide: createClosureHandler(args.onHide, { argName: 'onHide' }),
public/scripts/extensions/regex/index.js+1 -1
@@ -1639,7 +1639,7 @@ async function checkCharEmbeddedRegexScripts() {
16391639function notifyReloadCurrentChat(presetName) {
16401640 toastr.info(
16411641 t`Reload the chat for regex to take effect` + '<br><u>' + t`Click here to reload immediately` + '</u>',
16421642 t`Preset '${escapeHtml(presetName)}' contains enabled regex scripts`,
16431643 {
16441644 timeOut: 5000,
16451645 escapeHtml: false,
public/scripts/personas.js+6 -4
@@ -49,6 +49,7 @@ import {
4949 uuidv4,
5050 resolveAvatarData,
5151 findPersona,
52+ escapeHtml,
5253} from './utils.js';
5354import { debounce_timeout } from './constants.js';
5455import { FILTER_TYPES, FilterHelper } from './filters.js';
@@ -946,8 +947,9 @@ async function selectCurrentPersona({ toastPersonaNameChange = true } = {}) {
946947 const temporary = getPersonaTemporaryLockInfo();
947948 if (temporary.isTemporary) {
948949 toastr.info(t`This persona is only temporarily chosen. Click for more info.`, t`Temporary Persona`, {
949950 preventDuplicates: true, onclick: () => {
950- toastr.info(temporary.info.replaceAll('\n', '<br />'), t`Temporary Persona`, { escapeHtml: false });
951+ onclick: () => {
952+ toastr.info(escapeHtml(temporary.info).replaceAll('\n', '<br />'), t`Temporary Persona`, { escapeHtml: false });
951953 },
952954 });
953955 }
@@ -1116,9 +1118,9 @@ async function lockPersona(type = 'chat') {
11161118 if (power_user.persona_show_notifications) {
11171119 let additional = '';
11181120 if (unlinkedCharacters.length)
11191121 additional += `<br /><br />${t`Unlinked existing persona${unlinkedCharacters.length > 1 ? 's' : ''}: ${unlinkedCharacters.map(escapeHtml).join(', ')}`}`;
11201122 if (additional || !isPersonaPanelOpen()) {
11211123 toastr.success(t`User persona ${escapeHtml(name1)} is locked to character ${escapeHtml(name2)}${additional}`, t`Persona Locked`, { escapeHtml: false });
11221124 }
11231125 }
11241126 }
public/scripts/tags.js+5 -4
@@ -16,7 +16,7 @@ import {
1616import { FILTER_TYPES, FILTER_STATES, DEFAULT_FILTER_STATE, isFilterState, FilterHelper } from './filters.js';
1717
1818import { groupCandidatesFilter, groupMembersFilter, groups, selected_group } from './group-chats.js';
1919import { download, onlyUnique, parseJsonFile, uuidv4, getSortableDelay, flashHighlight, equalsIgnoreCaseAndAccents, includesIgnoreCaseAndAccents, removeFromArray, getFreeName, debounce, findChar, escapeHtml } from './utils.js';
2020import { power_user } from './power-user.js';
2121import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
2222import { SlashCommand } from './slash-commands/SlashCommand.js';
@@ -977,11 +977,12 @@ async function importTags(character, { importSetting = null } = {}) {
977977
978978 const tagsToImport = tagNamesToImport.map(tag => getTag(tag, { createNew: true }));
979979 const added = addTagsToEntity(tagsToImport, character.avatar);
980+ const tagNames = tagsToImport.map(x => escapeHtml(x.name)).join(', ');
980981
981982 if (added) {
982983 toastr.success(t`Imported tags:` + `<br />${tagsToImport.map(x => x.name).join(', ')tagNames}`, t`Importing Tags`, { escapeHtml: false });
983984 } else {
984985 toastr.error(t`Couldn't import tags:` + `<br />${tagsToImport.map(x => x.name).join(', ')tagNames}`, t`Importing Tags`, { escapeHtml: false });
985986 }
986987
987988 return added;
@@ -1124,7 +1125,7 @@ function getTag(tagName, { createNew = false } = {}) {
11241125function createNewTag(tagName) {
11251126 const existing = getTag(tagName);
11261127 if (existing) {
11271128 toastr.warning(`Cannot create new tag. A tag with the name already exists:<br />${escapeHtml(existing.name)}`, 'Creating Tag', { escapeHtml: false });
11281129 return existing;
11291130 }
11301131
public/scripts/utils.js+3 -3
@@ -2487,13 +2487,13 @@ export async function checkOverwriteExistingData(type, existingNames, name, { in
24872487 return true;
24882488 }
24892489
24902490 const overwrite = interactive && await Popup.show.confirm(`${type} ${actionName}`, `<p>A ${type.toLowerCase()} with the same name already exists:<br />${escapeHtml(existing)}</p>Do you want to overwrite it?`);
24912491 if (!overwrite) {
24922492 toastr.warning(`${type} ${actionName.toLowerCase()} cancelled. A ${type.toLowerCase()} with the same name already exists:<br />${escapeHtml(existing)}`, `${type} ${actionName}`, { escapeHtml: false });
24932493 return false;
24942494 }
24952495
24962496 toastr.info(`Overwriting Existing ${type}:<br />${escapeHtml(existing)}`, `${type} ${actionName}`, { escapeHtml: false });
24972497
24982498 // If there is an action to delete the existing data, do it, as the name might be slightly different so file name would not be the same
24992499 if (deleteAction) {