collab/mermaid/cypress/integration/other/xss.spec.jsblame
View source
6dd74de1import { imgSnapshotTest, mermaidUrl, utf8ToB64 } from '../../helpers/util.ts';
6dd74de2describe('XSS', () => {
6dd74de3 it('should handle xss in tags', () => {
6dd74de4 const str =
6dd74de5 'eyJjb2RlIjoiXG5ncmFwaCBMUlxuICAgICAgQi0tPkQoPGltZyBvbmVycm9yPWxvY2F0aW9uPWBqYXZhc2NyaXB0XFx1MDAzYXhzc0F0dGFja1xcdTAwMjhkb2N1bWVudC5kb21haW5cXHUwMDI5YCBzcmM9eD4pOyIsIm1lcm1haWQiOnsidGhlbWUiOiJkZWZhdWx0In19';
6dd74de6
6dd74de7 const url = mermaidUrl(str, {}, true);
6dd74de8
6dd74de9 cy.visit(url);
6dd74de10 cy.wait(1000).then(() => {
6dd74de11 cy.get('.mermaid').should('exist');
6dd74de12 });
6dd74de13 });
6dd74de14
6dd74de15 it('should not allow tags in the css', () => {
6dd74de16 const str =
6dd74de17 'eyJjb2RlIjoiJSV7aW5pdDogeyAnZm9udEZhbWlseSc6ICdcXFwiPjwvc3R5bGU+PGltZyBzcmM9eCBvbmVycm9yPXhzc0F0dGFjaygpPid9IH0lJVxuZ3JhcGggTFJcbiAgICAgQSAtLT4gQiIsIm1lcm1haWQiOnsidGhlbWUiOiJkZWZhdWx0IiwiZmxvd2NoYXJ0Ijp7Imh0bWxMYWJlbHMiOmZhbHNlfX0sInVwZGF0ZUVkaXRvciI6ZmFsc2V9';
6dd74de18
6dd74de19 const url = mermaidUrl(
6dd74de20 str,
6dd74de21 {
6dd74de22 theme: 'default',
6dd74de23 flowchart: {
6dd74de24 htmlMode: false,
6dd74de25 },
6dd74de26 },
6dd74de27 true
6dd74de28 );
6dd74de29
6dd74de30 cy.visit(url);
6dd74de31 cy.wait(1000).then(() => {
6dd74de32 cy.get('#the-malware').should('not.exist');
6dd74de33 });
6dd74de34 });
6dd74de35
6dd74de36 it('should handle xss in tags in non-html mode', () => {
6dd74de37 const str =
6dd74de38 'eyJjb2RlIjoiXG5ncmFwaCBMUlxuICAgICAgQi0tPkQoPGltZyBvbmVycm9yPWxvY2F0aW9uPWBqYXZhc2NyaXB0XFx1MDAzYXhzc0F0dGFja1xcdTAwMjhkb2N1bWVudC5kb21haW5cXHUwMDI5YCBzcmM9eD4pOyIsIm1lcm1haWQiOnsidGhlbWUiOiJkZWZhdWx0IiwiZmxvd2NoYXJ0Ijp7Imh0bWxMYWJlbHMiOmZhbHNlfX19';
6dd74de39
6dd74de40 const url = mermaidUrl(
6dd74de41 str,
6dd74de42 {
6dd74de43 theme: 'default',
6dd74de44 flowchart: {
6dd74de45 htmlMode: false,
6dd74de46 },
6dd74de47 },
6dd74de48 true
6dd74de49 );
6dd74de50
6dd74de51 cy.visit(url);
6dd74de52 cy.wait(1000);
6dd74de53
6dd74de54 cy.get('#the-malware').should('not.exist');
6dd74de55 });
6dd74de56
6dd74de57 it('should not allow changing the __proto__ attribute using config', () => {
6dd74de58 cy.visit('/xss2.html');
6dd74de59 cy.wait(1000);
6dd74de60 cy.get('#the-malware').should('not.exist');
6dd74de61 });
6dd74de62 it('should not allow manipulating htmlLabels into a false positive', () => {
6dd74de63 cy.visit('/xss4.html');
6dd74de64 cy.wait(1000);
6dd74de65 cy.get('#the-malware').should('not.exist');
6dd74de66 });
6dd74de67 it('should not allow manipulating antiscript to run javascript', () => {
6dd74de68 cy.visit('/xss5.html');
6dd74de69 cy.wait(1000);
6dd74de70 cy.get('#the-malware').should('not.exist');
6dd74de71 });
6dd74de72 it('should not allow manipulating antiscript to run javascript using onerror', () => {
6dd74de73 cy.visit('/xss6.html');
6dd74de74 cy.wait(1000);
6dd74de75 cy.get('#the-malware').should('not.exist');
6dd74de76 });
6dd74de77 it('should not allow manipulating antiscript to run javascript using onerror in state diagrams with dagre wrapper', () => {
6dd74de78 cy.visit('/xss8.html');
6dd74de79 cy.wait(1000);
6dd74de80 cy.get('#the-malware').should('not.exist');
6dd74de81 });
6dd74de82 it('should not allow manipulating antiscript to run javascript using onerror in state diagrams with dagre d3', () => {
6dd74de83 cy.on('uncaught:exception', (_err, _runnable) => {
6dd74de84 return false; // continue rendering even if there if mermaid throws an error
6dd74de85 });
6dd74de86 cy.visit('/xss9.html');
6dd74de87 cy.wait(1000);
6dd74de88 cy.get('#the-malware').should('not.exist');
6dd74de89 });
6dd74de90 it('should not allow manipulating antiscript to run javascript using onerror in state diagrams with dagre d3', () => {
6dd74de91 cy.visit('/xss10.html');
6dd74de92 cy.wait(1000);
6dd74de93 cy.get('#the-malware').should('not.exist');
6dd74de94 });
6dd74de95 it('should not allow manipulating antiscript to run javascript using onerror in state diagrams with dagre d3', () => {
6dd74de96 cy.visit('/xss11.html');
6dd74de97 cy.wait(1000);
6dd74de98 cy.get('#the-malware').should('not.exist');
6dd74de99 });
6dd74de100 it('should not allow manipulating antiscript to run javascript using onerror in state diagrams with dagre d3', () => {
6dd74de101 cy.visit('/xss12.html');
6dd74de102 cy.wait(1000);
6dd74de103 cy.get('#the-malware').should('not.exist');
6dd74de104 });
6dd74de105 it('should not allow manipulating antiscript to run javascript using onerror in state diagrams with dagre d3', () => {
6dd74de106 cy.visit('/xss13.html');
6dd74de107 cy.wait(1000);
6dd74de108 cy.get('#the-malware').should('not.exist');
6dd74de109 });
6dd74de110 it('should not allow manipulating antiscript to run javascript iframes in class diagrams', () => {
6dd74de111 cy.visit('/xss14.html');
6dd74de112 cy.wait(1000);
6dd74de113 cy.get('#the-malware').should('not.exist');
6dd74de114 });
6dd74de115 it('should sanitize cardinalities properly in class diagrams', () => {
6dd74de116 cy.visit('/xss18.html');
6dd74de117 cy.wait(1000);
6dd74de118 cy.get('#the-malware').should('not.exist');
6dd74de119 });
6dd74de120 it('should sanitize colons properly', () => {
6dd74de121 cy.visit('/xss20.html');
6dd74de122 cy.wait(1000);
6dd74de123 cy.get('a').click('');
6dd74de124 cy.wait(1000);
6dd74de125 cy.get('#the-malware').should('not.exist');
6dd74de126 });
6dd74de127 it('should sanitize colons properly', () => {
6dd74de128 cy.visit('/xss21.html');
6dd74de129 cy.wait(1000);
6dd74de130 cy.get('a').click('');
6dd74de131 cy.wait(1000);
6dd74de132 cy.get('#the-malware').should('not.exist');
6dd74de133 });
6dd74de134 it('should sanitize backticks in class names properly', () => {
6dd74de135 cy.visit('/xss24.html');
6dd74de136 cy.wait(1000);
6dd74de137 cy.get('#the-malware').should('not.exist');
6dd74de138 });
6dd74de139 it('should sanitize backticks block diagram labels properly', () => {
6dd74de140 cy.visit('/xss25.html');
6dd74de141 cy.wait(1000);
6dd74de142 cy.get('#the-malware').should('not.exist');
6dd74de143 });
6dd74de144
6dd74de145 it('should sanitize icon labels in architecture diagrams', () => {
6dd74de146 const str = JSON.stringify({
6dd74de147 code: `architecture-beta
6dd74de148 group api(cloud)[API]
6dd74de149 service db "<img src=x onerror=\\"xssAttack()\\">" [Database] in api`,
6dd74de150 });
6dd74de151 imgSnapshotTest(utf8ToB64(str), {}, true);
6dd74de152 cy.wait(1000);
6dd74de153 cy.get('#the-malware').should('not.exist');
6dd74de154 });
6dd74de155
6dd74de156 it('should sanitize katex blocks', () => {
6dd74de157 const str = JSON.stringify({
6dd74de158 code: `sequenceDiagram
6dd74de159 participant A as Alice<img src="x" onerror="xssAttack()">$$\\text{Alice}$$
6dd74de160 A->>John: Hello John, how are you?`,
6dd74de161 });
6dd74de162 imgSnapshotTest(utf8ToB64(str), {}, true);
6dd74de163 cy.wait(1000);
6dd74de164 cy.get('#the-malware').should('not.exist');
6dd74de165 });
6dd74de166
6dd74de167 it('should sanitize labels', () => {
6dd74de168 const str = JSON.stringify({
6dd74de169 code: `erDiagram
6dd74de170 "<img src=x onerror=xssAttack()>" ||--|| ENTITY2 : "<img src=x onerror=xssAttack()>"
6dd74de171 `,
6dd74de172 });
6dd74de173 imgSnapshotTest(utf8ToB64(str), {}, true);
6dd74de174 cy.wait(1000);
6dd74de175 cy.get('#the-malware').should('not.exist');
6dd74de176 });
6dd74de177});