Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: HMAC verification on IPN callback for security #561

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

Benjamin-Freoua-Alma
Copy link
Member

Reason for change

Linear task

Code changes

We add the call function to isHmacValidated in php client to check is the IPN callback is signed by Alma before to validate the order by IPN

How to test

As a reviewer, you are encouraged to test the PR locally.

Make an order, close the page before the return validation payment
Call the ipn callback with some other browser or API Client to check if the IPN need the Alma signature

Checklist for authors and reviewers

  • The title of the PR uses business wording, not technical jargon, for the changelog readers to understand it
  • The PR implements the changes asked in the referenced task / issue
  • The automated tests are compliant with the testing strategy
  • The tests are relevant, and cover the corner/error cases, not only the happy path
  • You understand the impact of this PR on existing code/features
  • The changes include adequate logging and Datadog traces
  • Documentation is updated (API, developer documentation, ADR, Notion...)

Non applicable

@github-actions github-actions bot added the type: feature New feature label Aug 13, 2024
@Benjamin-Freoua-Alma Benjamin-Freoua-Alma self-assigned this Sep 17, 2024
@Benjamin-Freoua-Alma Benjamin-Freoua-Alma marked this pull request as ready for review September 17, 2024 12:49
@Benjamin-Freoua-Alma Benjamin-Freoua-Alma requested a review from a team as a code owner September 17, 2024 12:49

This comment has been minimized.

This comment has been minimized.

alma/controllers/front/ipn.php Show resolved Hide resolved
alma/controllers/front/ipn.php Show resolved Hide resolved
alma/controllers/front/ipn.php Show resolved Hide resolved
alma/controllers/front/ipn.php Outdated Show resolved Hide resolved
alma/exceptions/PaymentValidationException.php Outdated Show resolved Hide resolved
alma/lib/Validators/PaymentValidation.php Outdated Show resolved Hide resolved
alma/lib/Validators/PaymentValidation.php Outdated Show resolved Hide resolved
$this->paymentValidation->checkSignature(self::PAYMENT_ID, self::API_KEY, self::WRONG_SIGNATURE);
}

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

no throws on this test - if you remove true in method, juste test no exception thrown

Copy link
Member Author

Choose a reason for hiding this comment

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

@Francois-Gomis I'm not sure to understand

Copy link
Collaborator

Choose a reason for hiding this comment

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

In your comment you have a throws decorator

*/
public function checkSignature($paymentId, $apiKey, $signature)
{
if (!$paymentId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think this test is necessary only for log, isHmacValidated test if params are string

Copy link
Member Author

Choose a reason for hiding this comment

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

@Francois-Gomis Do you want I replace throw by log ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, need, if an error occur, you have exception log. If no error no logs

This comment has been minimized.

This comment has been minimized.

/**
* @return array[]
*/
public function checkSignatureWrongParamsDataProvider()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure, api is always a string '' not null ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@Francois-Gomis I added the test with null

$this->paymentValidation->checkSignature(self::PAYMENT_ID, self::API_KEY, self::WRONG_SIGNATURE);
}

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

In your comment you have a throws decorator

Copy link

⏳E2E tests are currently running.
➡️ You can follow their progression here.

Copy link

sonarcloud bot commented Sep 19, 2024

Copy link

❌ E2E tests have failed.
➡️ You can find the results here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants