From d99bc61001bd37a46996c331e92f1ec43a25eb19 Mon Sep 17 00:00:00 2001 From: ltthienn Date: Thu, 21 Sep 2023 16:54:58 +0700 Subject: [PATCH 1/5] Add csp tests --- cypress/e2e/specs/csp.e2e.cy.ts | 95 +++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 cypress/e2e/specs/csp.e2e.cy.ts diff --git a/cypress/e2e/specs/csp.e2e.cy.ts b/cypress/e2e/specs/csp.e2e.cy.ts new file mode 100644 index 0000000000..b65d70a5ca --- /dev/null +++ b/cypress/e2e/specs/csp.e2e.cy.ts @@ -0,0 +1,95 @@ +import { SwapPage, TokenCatalog } from "../pages/swap-page.po.cy" +import { DEFAULT_URL, TAG } from "../selectors/constants.cy" + +const tokenCatalog = new TokenCatalog() + +describe('CSP', { tags: TAG.regression }, () => { + beforeEach(() => { + cy.on('window:load', (win) => cy.stub(win.console, 'log').as('log')) + SwapPage.open(DEFAULT_URL) + }) + + describe('Search token in Token Catalog', { tags: TAG.regression }, () => { + beforeEach(() => { + SwapPage.selectTokenIn() + }) + it('injecting ') + cy.get('@log').should('not.have.been.called') + }) + + it('injects XSS via img onerror attribute', () => { tokenCatalog.searchToken('KNC') cy.get('@log').should('not.have.been.called') }) @@ -33,6 +39,14 @@ describe('CSP', { tags: TAG.smoke }, () => { SwapPage.goToPoolPage() }) it('injecting ') + cy.get('@log').should('not.have.been.called') + }) + + it('injects XSS via img onerror attribute', () => { cy.get(PoolLocators.txtSearch, { timeout: 10000 }) .should('be.visible') .click() @@ -53,7 +67,16 @@ describe('CSP', { tags: TAG.smoke }, () => { beforeEach(() => { SwapPage.goToMyPoolsPage() }) + it('injecting ') + cy.get('@log').should('not.have.been.called') + }) + + it('injects XSS via img onerror attribute', () => { cy.get(MyPoolLocators.txtSearch, { timeout: 10000 }) .should('be.visible') .click() @@ -75,7 +98,16 @@ describe('CSP', { tags: TAG.smoke }, () => { beforeEach(() => { SwapPage.goToFarmPage() }) + it('injecting ') + cy.get('@log').should('not.have.been.called') + }) + + it('injects XSS via img onerror attribute', () => { cy.get(FarmLocators.txtSearch, { timeout: 10000 }) .should('be.visible') .click() From 4f92edc1768663a3ea8d854b23d458ceff868af5 Mon Sep 17 00:00:00 2001 From: ltthienn Date: Wed, 4 Oct 2023 12:03:58 +0700 Subject: [PATCH 5/5] update selectors --- cypress/e2e/selectors/selectors.cy.ts | 8 ++++---- cypress/support/selectTokenCommands.ts | 4 ++-- src/components/SearchModal/CurrencySearch.tsx | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cypress/e2e/selectors/selectors.cy.ts b/cypress/e2e/selectors/selectors.cy.ts index 3e88fea966..ea4ee1d6a5 100644 --- a/cypress/e2e/selectors/selectors.cy.ts +++ b/cypress/e2e/selectors/selectors.cy.ts @@ -1,7 +1,7 @@ export const TokenCatalogLocators = { dropdownTokenIn: '[data-testid=swap-currency-input] [data-testid=token-symbol-container]', dropdownTokenOut: '[data-testid=swap-currency-output] [data-testid=token-symbol-container]', - txtToken: '[data-testid=token-search-input]', + txtSearch: '[data-testid=search-input]', lblFavoriteToken: '[data-testid=favorite-token]', lblRowInWhiteList: '[data-testid=token-item]', lblNotFound: '[data-testid=no-token-result]', @@ -47,13 +47,13 @@ export const FarmLocators = { } export const PoolLocators = { - txtSearch: '[data-testid=input-search]' + txtSearch: '[data-testid=search-input]' } export const MyPoolLocators = { - txtSearch: '[data-testid=input-search]' + txtSearch: '[data-testid=search-input]' } export const MyEarningLocators = { - txtSearch: '[data-testid=input-search]' + txtSearch: '[data-testid=search-input]' } \ No newline at end of file diff --git a/cypress/support/selectTokenCommands.ts b/cypress/support/selectTokenCommands.ts index 098d334d3e..efa0530ff6 100644 --- a/cypress/support/selectTokenCommands.ts +++ b/cypress/support/selectTokenCommands.ts @@ -39,7 +39,7 @@ Cypress.Commands.add('selectTokenOut', () => { }) Cypress.Commands.add('searchToken', (value) => { - cy.get(TokenCatalogLocators.txtToken).should('be.visible').type(value) + cy.get(TokenCatalogLocators.txtSearch).should('be.visible').type(value) }) Cypress.Commands.add('selectTokenBySymbol', (value) => { @@ -74,7 +74,7 @@ Cypress.Commands.add('deleteImportedToken', (value: string) => { cy.searchToken(value) cy.wait(1000) cy.get(TokenCatalogLocators.lblRowInWhiteList).children().find(TokenCatalogLocators.iconRemoveImportedToken).click() - cy.get(TokenCatalogLocators.txtToken).clear() + cy.get(TokenCatalogLocators.txtSearch).clear() }) diff --git a/src/components/SearchModal/CurrencySearch.tsx b/src/components/SearchModal/CurrencySearch.tsx index c25bf3038e..e42d3b5a7d 100644 --- a/src/components/SearchModal/CurrencySearch.tsx +++ b/src/components/SearchModal/CurrencySearch.tsx @@ -438,7 +438,7 @@ export function CurrencySearch({