Skip to content

Potential fix for code scanning alert no. 1: Unvalidated dynamic method call #36

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stargazer4
Copy link
Contributor

Potential fix for https://github.com/octodemo/node-calculator-v11-sk/security/code-scanning/1

To fix the problem, we should ensure that the method name provided by the user (req.query.operation) is only used to access own properties of the operations object, and that the resulting value is a function. This can be done by replacing the current lookup and check with a combination of Object.prototype.hasOwnProperty.call(operations, req.query.operation) and typeof operations[req.query.operation] === 'function'. This ensures that only explicitly defined operations are allowed, and that the value is a function before calling it. The changes should be made in the calculate function in api/controller.js, specifically around lines 25–29.


Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…od call

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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.

1 participant