Skip to content

Conversation

@pannepu
Copy link

@pannepu pannepu commented May 22, 2023

Fixing snyk issue

JIRA ID | Git Issue

DTFPCHG-178

Change Type

  • Bug fix (is this a backward compatible change?)
  • New feature (is this a backward compatible change?)
  • Breaking change (is this a non-backward compatible change?)
  • DB changes (add scripts in the sql/migrations/{date} folder)

Change Impact

Summary

  • The SAST tool [Snyk] has identified security risks with code snippet in this repository.
  • http.request method is being used in lib/api-requestor.js file which is the root cause for this issue.
  • We are mainly using this for local testing since we do not support http in the Prod environment.
  • Removed the support for making the request using http protocol.
  • At any point in time if we want to continue testing in our local, we can go ahead and add this code snippet.

Demo

image
image
image

Notes

  • Updated the lib/api-requestor.js file to remove the support for http protocol.

Testing Instructions

  • Try to submit a dispute in our local environment using http protocol. Configure the required properties in the lib/index.js
  • Observe that we would be able to submit the test dispute as long as http protocol is supported in our SDK.
  • Now go ahead and remove the http protocol support from lib/api-requestor.js file and try submitting a test dispute.
  • Observe that the request would fail with the above mentioned error (in the screenshot).

@jagadeeshdeepak-pp
Copy link

@pannepu can you document this and attach it to the setup page here?
https://engineering.paypalcorp.com/confluence/display/RIAC/CH+-+Local+Setup

if (this._chargehound.options.protocol === 'https://') {
req = https.request(reqOpts).setTimeout(this.getTimeout())
connectEv = 'secureConnect'
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not see if the env is local or not and then use the protocol based on that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@pannepu
Copy link
Author

pannepu commented May 23, 2023

req = https.request(reqOpts).setTimeout(this.getTimeout())
connectEv = 'secureConnect'
} else {
} else if ((this._chargehound.options.protocol === 'http://') && (this._chargehound.options.host === 'localhost')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python dont have else if. please change it to elif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with deepak, can we check current values of protocol for all environment (local, stage, prod) and use it accordingly here instead of relying on protocol value

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python dont have else if. please change it to elif

These changes are done in javascript file.

lib/index.js Outdated
const CHARGEHOUND_HOST = 'api.chargehound.com'
const CHARGEHOUND_BASE_PATH = '/v1/'
const CHARGEHOUND_TIMEOUT = 60 * 1000
const CHARGEHOUND_ENV = 'prod'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const CHARGEHOUND_ENV = 'prod'
const CHARGEHOUND_DEFAULT_ENV = 'prod'

Fixing snyk issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants