Skip to content

Commit

Permalink
Add minimal XSS test
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienClairembault authored and cedric-anne committed Sep 18, 2024
1 parent d366caf commit ffba369
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/cypress/e2e/xss.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2024 Teclib' and contributors.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

const xss_payload = '<script>throw new Error("XSS");</script>';

describe('XSS tests for CRUD and search operations', () => {
beforeEach(() => {
cy.login();
});

it("Can't inject XSS into an item name", () => {
// Go to entity page
cy.visit('/front/entity.form.php');
const unique_id = (new Date()).getTime();
const name = unique_id + xss_payload;

// Create an entity with a XSS payload
cy.findByRole('textbox', {'name': "Name"}).type(name);
cy.findByRole('button', {'name': "Add"}).click();

// Go to created entity
cy.findByRole('alert')
.should('contain.text', 'Item successfully added:')
.and('contain.text', name)
;
cy.findByRole('link', {'name': name}).click();

// Check name
cy.findByRole('textbox', {'name': "Name"}).should(
'have.value',
name
);

// Search for the entity
cy.visit(`/front/entity.php?criteria[0][link]=AND&criteria[0][field]=14&criteria[0][searchtype]=contains&criteria[0][value]=${name}`);
cy.findAllByText(name).should('exist').and('have.length', 2);
});
});

0 comments on commit ffba369

Please sign in to comment.