Home > database >  Encrypt/Mask sensitive data on git push (Encryprted/masked display on remote repo)
Encrypt/Mask sensitive data on git push (Encryprted/masked display on remote repo)

Time:02-02

I have a Cypress code that contains sensitive header that I wish to be masked/decrypted

cy.request({
    method: 'GET',
    url: 'https://sample-url',
    headers: {
        'key': 'value'
    }
})

Is there a way whenever we push on remote, my desired values gets encrypted (e.g. the headers on the above example).

CodePudding user response:

There's nothing I can think of that will encrypt and decrypt values automatically via git push/fetch. That's probably not the direction you want to go anyway.

The more simple way dealing with sensitive values is by storing them in environment variables and to not commit these to version control.

With Cypress, there's several ways to get environment vars into tests, but one easy way is with a cypress.env.json file. This file would be listed inside your .gitignore.

The env file would look like the following:

// cypress.env.json
{
  "secretKey": "value"
}

And your code would call it like this

// Code
cy.request({
    method: 'GET',
    url: 'https://sample-url',
    headers: {
        'key': Cypress.env('secretKey');
    }
})

The only thing you need to make sure, if you run the tests in a pipeline, you have to set the environmet variables before running the tests.

Here's another link that I think could help

https://glebbahmutov.com/blog/keep-passwords-secret-in-e2e-tests/

  • Related