From 6f800be33be08d543f27b1fc995b23a4fdeecd01 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Thu, 23 Dec 2021 11:03:07 +0100 Subject: [PATCH] Fix for issue with links from actors --- cypress/platform/xss15.html | 4 +-- src/diagrams/common/common.js | 34 ++++++++++++++++----- src/diagrams/common/common.spec.js | 47 +++++++++++++++++++++++++++++- 3 files changed, 74 insertions(+), 11 deletions(-) diff --git a/cypress/platform/xss15.html b/cypress/platform/xss15.html index a2d882dffe..94506def5f 100644 --- a/cypress/platform/xss15.html +++ b/cypress/platform/xss15.html @@ -70,7 +70,7 @@ // fontFamily: 'courier', fontSize: 18, curve: 'basis', - securityLevel: 'strict ', + securityLevel: 'strict', startOnLoad: false, secure: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize'], // themeVariables: {relationLabelColor: 'red'} @@ -90,7 +90,7 @@ var diagram = `sequenceDiagram participant John links John: {"XSS": "javas`; -diagram += 'cript:alert(window.opener.document.domain)"}'; +diagram += `cript:alert('AudioParam')"}`; // var diagram = "stateDiagram-v2\n"; // diagram += " { return str.split('#br#'); }; +export const removeEscapes = (text) => { + let newStr = text.replace(/\\u[\dA-F]{4}/gi, function (match) { + return String.fromCharCode(parseInt(match.replace(/\\u/g, ''), 16)); + }); + + console.log(newStr); + + newStr = newStr.replace(/\\x([0-9a-f]{2})/gi, (_, c) => String.fromCharCode(parseInt(c, 16))); + newStr = newStr.replace(/\\[\d\d\d]{3}/gi, function (match) { + return String.fromCharCode(parseInt(match.replace(/\\/g, ''), 8)); + }); + newStr = newStr.replace(/\\[\d\d\d]{2}/gi, function (match) { + return String.fromCharCode(parseInt(match.replace(/\\/g, ''), 8)); + }); + + return newStr; +}; + /** * Removes script tags from a text * @@ -40,13 +58,12 @@ export const removeScript = (txt) => { break; } } - - rs = rs.replace(/script>/gi, '#'); - rs = rs.replace(/script>/gi, '#'); - rs = rs.replace(/javascript:/gi, '#'); - rs = rs.replace(/onerror=/gi, 'onerror:'); - rs = rs.replace(/