Potential fix for code scanning alert no. 84: Unvalidated dynamic method call#5746
Potential fix for code scanning alert no. 84: Unvalidated dynamic method call#5746christopherholland-workday wants to merge 1 commit intomainfrom
Conversation
…hod call Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Summary of ChangesHello @christopherholland-workday, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request aims to resolve a security vulnerability identified by a code scanning alert. The changes introduce robust input validation within the rate limiter functions, Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Potential fix for https://github.com/FlowiseAI/Flowise/security/code-scanning/84
In general, to fix this issue you must ensure that the function you dynamically call is both (a) associated with an allowed identifier and (b) actually a function that is safe to invoke. For objects used as maps, that means rejecting keys that are not own properties and confirming the retrieved value has the expected type before invocation; alternatively, you can migrate to a
Mapand usehas/getwith the same checks.The best minimal fix here, without changing existing functionality, is to add validation around the dynamic lookup and invocation in
getRateLimiter(and keepgetRateLimiterByIdsafe as well). Specifically, after you deriveidfromreq.params.id, you should: (1) ensureidis a non-empty string, (2) ensurethis.rateLimitershas thatidas an own property (not inherited from the prototype chain) usingObject.prototype.hasOwnProperty.call, and (3) ensurethis.rateLimiters[id]is a function before calling it. If any of these checks fail, fall back tonext()so that no unexpected method is invoked or runtime error thrown. This preserves current behavior for valid IDs (they’re still routed to the correct rate limiter) while hardening the code against malicious or malformed input.Concretely, in
packages/server/src/utils/rateLimit.ts, you need to modify the body ofgetRateLimiter()(lines 128–135) to add these checks before callingidRateLimiter. You can also slightly tightengetRateLimiterByIdin the same style (even though itsidparameter is not user-controlled in this context) for consistency and extra safety. No new imports are required; the validation uses built-inObject.prototype.hasOwnProperty.Suggested fixes powered by Copilot Autofix. Review carefully before merging.