Skip to content

Fix Deprecation Warning in has_environment_scope

Jason Goodman requested to merge has-environment-deprecation into master

What does this MR do?

Deprecation warnings like the following have started to appear in the test suite output when the code under test invokes the has_environment_scope method:

DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "CASE environment_scope\n WHEN '*' THEN 0\n WHEN 'production' THEN 2\n ELSE 1\nEND ASC\n". Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql().

This MR wraps the raw SQL in Arel.sql, suppressing the deprecation warning.

This raw SQL uses values from user input. However, the values are quoted using ActiveRecord.connection.quote:

https://gitlab.com/gitlab-org/gitlab-ee/blob/5eca7a642e143b455267b9dcdb629e682e7fc36d/ee/app/models/concerns/has_environment_scope.rb#L47

Does this MR meet the acceptance criteria?

Conformity

Performance and testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Jason Goodman

Merge request reports

Loading