Skip to content

Conversation

RajeshPaul38
Copy link
Contributor

Potential fix for https://github.com/chef/supermarket/security/code-scanning/30

To fix the problem, remove the use of .constantize on user-provided input. Instead, explicitly map allowed user input values to their corresponding classes using a Ruby hash. For example, use a lookup table: ALLOWED_RESOURCE_TYPES = {'Cookbook' => Cookbook, 'Tool' => Tool} and do resource_class = ALLOWED_RESOURCE_TYPES[params[:resourceable_type]]. Then, only proceed if the mapping is successful.

In this file, there are two places using .constantize:

  • In create, on lines 35-38, it is already protected by a whitelist array, but should use the mapping approach.
  • In destroy_group, on lines 76-79, similar direct use of .constantize should be replaced with a safe mapping.

Define the mapping at the top of the class, and use it both in create and destroy_group. Do not rely on dynamic lookup.


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

code scanning link: https://github.com/chef/supermarket/security/code-scanning/30

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment on lines 4 to 7
ALLOWED_RESOURCE_TYPES = {
'Cookbook' => Cookbook,
'Tool' => Tool
}.freeze
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use double quoted keys

Signed-off-by: Rajesh Paul <[email protected]>
@RajeshPaul38 RajeshPaul38 changed the base branch from main to rp/codeql-fix September 26, 2025 07:01
Copy link

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