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

Fix incorrect signature hash during verify return url #16

Merged
merged 4 commits into from
Jul 2, 2024

Conversation

lehuygiang28
Copy link
Owner

@lehuygiang28 lehuygiang28 commented Jul 2, 2024

Fix verify failed due to amount issue

This pull request fixes the issue by removing the division operation before verifying the signature.

fixes #15

Type of Change

Please check the type of change your PR introduces:

  • Bugfix
  • New feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Testing

  • Try to convert vnp_Amount to a string. It will go directly to the if block, so it will not be divided anymore. Verify that it worked!

Does this introduce a breaking change?

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

Related Issues or References

#15

Summary by Sourcery

This pull request fixes an issue with the signature verification by removing an unnecessary division operation on the amount. It also updates the 'Buy Me A Coffee' button in the documentation and adds an English translation for a comment in the type definition file.

  • Bug Fixes:
    • Fixed incorrect signature hash during verify return URL by removing the division operation on the amount.
  • Documentation:
    • Updated the 'Buy Me A Coffee' button in README.md and README_en-US.md with a new image and link format.
    • Added English translation for the 'Payment amount' comment in the return-from-vnpay.type.ts file.

Summary by CodeRabbit

  • Documentation

    • Enhanced the "Buy Me A Coffee" link in README.md and README_en-US.md with a more sophisticated button link.
  • Bug Fixes

    • Corrected the vnp_Amount property calculation in the VNPay class by removing unnecessary division by 100.
  • Chores

    • Added a comment specifying the payment amount in the ReturnQueryFromVNPay type.

When parsing a number string to a number, it can be divided twice. One of these divisions occurs before verifying the hash, causing the verification to fail.

#15
Copy link

vercel bot commented Jul 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vnpay ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2024 1:20pm

Copy link

coderabbitai bot commented Jul 2, 2024

Walkthrough

The updates primarily improve the documentation and fix a significant bug. The README.md and README_en-US.md files now feature a more sophisticated "Buy Me A Coffee" button link. A documentation comment specifying the payment amount was added to the ReturnQueryFromVNPay type. The most critical fix involves removing an erroneous division by 100 in the VNPay class, which caused signature mismatches during URL verification.

Changes

Files Change Summary
README.md, README_en-US.md Replaced the "Buy Me A Coffee" image link with a new button link.
src/types/return-from-vnpay.type.ts Added a comment in English specifying the payment amount in the ReturnQueryFromVNPay type.
src/vnpay.ts Removed the division operation by 100 on the vnp_Amount property to fix signature mismatches.

Assessment against linked issues

Objective (#) Addressed Explanation
Incorrect signature hash during verify return URL (#15)

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are currently opted into early access features by default.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

sourcery-ai bot commented Jul 2, 2024

Reviewer's Guide by Sourcery

This pull request addresses a bug where the signature verification failed due to an incorrect amount calculation. The fix involves removing the division operation on vnp_Amount before verifying the signature. Additionally, the 'Buy Me A Coffee' button in the README files has been updated to use a new image source and styling. An English comment was also added for the vnp_Amount field in the type definition.

File-Level Changes

Files Changes
README.md
README_en-US.md
Updated the 'Buy Me A Coffee' button to use a new image source and styling in both README files.
src/vnpay.ts
src/types/return-from-vnpay.type.ts
Fixed the signature verification issue by removing the division operation on vnp_Amount and added an English comment for the vnp_Amount field.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @lehuygiang28 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 2 issues found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

src/vnpay.ts Show resolved Hide resolved
src/types/return-from-vnpay.type.ts Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README_en-US.md Outdated Show resolved Hide resolved
@lehuygiang28 lehuygiang28 self-assigned this Jul 2, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 1f840f4 and e36d088.

Files selected for processing (4)
  • README.md (1 hunks)
  • README_en-US.md (1 hunks)
  • src/types/return-from-vnpay.type.ts (1 hunks)
  • src/vnpay.ts (1 hunks)
Additional context used
Path-based instructions (4)
README_en-US.md (1)

Pattern **/*.md: Review the Markdown files to ensure they are well-structured follow Docusaurus's best practices, easy to read, and contain accurate and up-to-date information. Check for proper formatting, grammar, and spelling. Ensure that the content is relevant and engaging for the target audience. Highlight any inconsistencies or errors and suggest improvements to enhance the overall quality of the documentation.

README.md (1)

Pattern **/*.md: Review the Markdown files to ensure they are well-structured follow Docusaurus's best practices, easy to read, and contain accurate and up-to-date information. Check for proper formatting, grammar, and spelling. Ensure that the content is relevant and engaging for the target audience. Highlight any inconsistencies or errors and suggest improvements to enhance the overall quality of the documentation.

src/types/return-from-vnpay.type.ts (1)

Pattern **/*.ts: Review the TypeScript code of the NPM package to ensure it adheres to the principles of awesome and clean code. This includes proper use of functions, classes, modules. Also, ensure the code follows best practices for package development, such as clear and concise documentation, proper error handling, and efficient data structures and algorithms. The code should also conform to the ESLint rules configured in the codebase. Highlight any deviations and suggest appropriate corrections. Using design patterns that promote code reusability and readability is encouraged.

src/vnpay.ts (1)

Pattern **/*.ts: Review the TypeScript code of the NPM package to ensure it adheres to the principles of awesome and clean code. This includes proper use of functions, classes, modules. Also, ensure the code follows best practices for package development, such as clear and concise documentation, proper error handling, and efficient data structures and algorithms. The code should also conform to the ESLint rules configured in the codebase. Highlight any deviations and suggest appropriate corrections. Using design patterns that promote code reusability and readability is encouraged.

Markdownlint
README_en-US.md

80-80: Expected: h3; Actual: h4
Heading levels should only increment by one level at a time

(MD001, heading-increment)


80-80: Punctuation: '.'
Trailing punctuation in heading

(MD026, no-trailing-punctuation)


82-82: Element: a
Inline HTML

(MD033, no-inline-html)


83-83: Element: img
Inline HTML

(MD033, no-inline-html)


83-83: null
Images should have alternate text (alt text)

(MD045, no-alt-text)

README.md

79-79: Expected: h3; Actual: h4
Heading levels should only increment by one level at a time

(MD001, heading-increment)


79-79: Punctuation: '.'
Trailing punctuation in heading

(MD026, no-trailing-punctuation)


81-81: Element: a
Inline HTML

(MD033, no-inline-html)


82-82: Element: img
Inline HTML

(MD033, no-inline-html)


82-82: null
Images should have alternate text (alt text)

(MD045, no-alt-text)

LanguageTool
README.md

[misspelling] ~79-~79: Possible spelling mistakes found.
Context: ...Hỗ trợ

Thư viện VNPay là một dự án mã nguồn mở và miễn phí. Nếu bạn thấy nó h...

(EN_MULTITOKEN_SPELLING_TWO)

Additional comments not posted (2)
src/types/return-from-vnpay.type.ts (1)

7-7: LGTM!

The addition of the English comment enhances code clarity and documentation.

src/vnpay.ts (1)

261-261: LGTM!

The removal of the division operation on vnp_Amount ensures that the signature verification matches correctly, addressing the bug mentioned in the PR objectives.

README_en-US.md Outdated Show resolved Hide resolved
README_en-US.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between e36d088 and 4b171fc.

Files selected for processing (2)
  • README.md (3 hunks)
  • README_en-US.md (3 hunks)
Additional context used
Path-based instructions (2)
README_en-US.md (1)

Pattern **/*.md: Review the Markdown files to ensure they are well-structured follow Docusaurus's best practices, easy to read, and contain accurate and up-to-date information. Check for proper formatting, grammar, and spelling. Ensure that the content is relevant and engaging for the target audience. Highlight any inconsistencies or errors and suggest improvements to enhance the overall quality of the documentation.

README.md (1)

Pattern **/*.md: Review the Markdown files to ensure they are well-structured follow Docusaurus's best practices, easy to read, and contain accurate and up-to-date information. Check for proper formatting, grammar, and spelling. Ensure that the content is relevant and engaging for the target audience. Highlight any inconsistencies or errors and suggest improvements to enhance the overall quality of the documentation.

Markdownlint
README_en-US.md

43-43: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)


82-82: Element: a
Inline HTML

(MD033, no-inline-html)


83-83: Element: img
Inline HTML

(MD033, no-inline-html)

README.md

43-43: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)


81-81: Element: a
Inline HTML

(MD033, no-inline-html)


82-82: Element: img
Inline HTML

(MD033, no-inline-html)

LanguageTool
README.md

[misspelling] ~79-~79: Possible spelling mistakes found.
Context: ... Hỗ trợ

Thư viện VNPay là một dự án mã nguồn mở và miễn phí. Nếu bạn thấy nó h...

(EN_MULTITOKEN_SPELLING_TWO)

README_en-US.md Show resolved Hide resolved
README_en-US.md Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
@lehuygiang28 lehuygiang28 merged commit 9b25568 into main Jul 2, 2024
6 checks passed
@lehuygiang28 lehuygiang28 deleted the fix_amount_divided_twice branch July 2, 2024 13:58
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.

[Bug] Incorrect signature hash during verify return url
1 participant