From 3dab60504bb82d6b6897ac6ec804a81afbb752c6 Mon Sep 17 00:00:00 2001 From: esrakartalOpt Date: Thu, 19 Nov 2026 16:49:18 -0600 Subject: [PATCH 1/3] [FSSDK-13474] Fix Arnica findings: artipacked workflows, MD5 hash, test class false positive - Add persist-credentials: false to the actions/checkout steps in ruby.yml and integration_test.yml so the GitHub token is not left in .git/config. - Use SHA256 instead of MD5 for the CMAB attributes cache fingerprint. - Add a nosemgrep comment on the TestBucketer test class (not a Rails model). Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/integration_test.yml | 3 +++ .github/workflows/ruby.yml | 2 ++ lib/optimizely/cmab/cmab_service.rb | 8 ++++---- spec/bucketing_holdout_spec.rb | 2 ++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index 0b8d086e..d86e33be 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -19,6 +19,9 @@ jobs: with: # You should create a personal access token and store it in your repository token: ${{ secrets.CI_USER_TOKEN }} + # The token is only needed for this checkout. Later steps pass it explicitly via env + # and do not use git, so do not leave it in .git/config. + persist-credentials: false repository: 'optimizely/travisci-tools' path: 'home/runner/travisci-tools' ref: 'master' diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 971eea92..d1111f19 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -28,6 +28,8 @@ jobs: ruby: [ '3.0.0', '3.1.0', '3.2.0', '3.3.0' ] steps: - uses: actions/checkout@v3 + with: + persist-credentials: false - name: Set up Ruby ${{ matrix.ruby }} uses: ruby/setup-ruby@v1 with: diff --git a/lib/optimizely/cmab/cmab_service.rb b/lib/optimizely/cmab/cmab_service.rb index 88f2825f..14706d53 100644 --- a/lib/optimizely/cmab/cmab_service.rb +++ b/lib/optimizely/cmab/cmab_service.rb @@ -205,16 +205,16 @@ def get_cache_key(user_id, rule_id) end def hash_attributes(attributes) - # Generates an MD5 hash for a given attributes hash. + # Generates a SHA256 hash for a given attributes hash. # # The method sorts the attributes by key, serializes them to a JSON string, - # and then computes the MD5 hash of the resulting string. This ensures that + # and then computes the SHA256 hash of the resulting string. This ensures that # the hash is consistent regardless of the original key order in the input hash. # # @param attributes [Hash] The attributes to be hashed. - # @return [String] The MD5 hash of the sorted and serialized attributes. + # @return [String] The SHA256 hash of the sorted and serialized attributes. sorted_attrs = JSON.generate(attributes.sort.to_h) - Digest::MD5.hexdigest(sorted_attrs) + Digest::SHA256.hexdigest(sorted_attrs) end end end diff --git a/spec/bucketing_holdout_spec.rb b/spec/bucketing_holdout_spec.rb index 4ddf1f67..cd26176f 100644 --- a/spec/bucketing_holdout_spec.rb +++ b/spec/bucketing_holdout_spec.rb @@ -21,6 +21,8 @@ require 'optimizely/logger' # Helper class for testing with controlled bucket values +# This is a plain Ruby test double, not a Rails model, so the mass assignment (attr_accessible) rule does not apply. +# nosemgrep: ruby.lang.security.model-attributes-attr-accessible.model-attributes-attr-accessible class TestBucketer < Optimizely::Bucketer def initialize(logger) super(logger) From be5f0fe9f089fe10fd3b148967e2f517acd54133 Mon Sep 17 00:00:00 2001 From: esrakartalOpt Date: Thu, 19 Nov 2026 17:00:44 -0600 Subject: [PATCH 2/3] [FSSDK-13474] Use Ruby series versions in CI matrix ubuntu-latest is now Ubuntu 26.04, which only provides the latest patch of each Ruby series, so exact versions like 3.1.0 fail in setup-ruby. Use 3.0, 3.1, 3.2 and 3.3 so the latest patch is always selected, and update the rubocop condition for Ruby 3.0 to match. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/ruby.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index d1111f19..94bedd58 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby: [ '3.0.0', '3.1.0', '3.2.0', '3.3.0' ] + ruby: [ '3.0', '3.1', '3.2', '3.3' ] steps: - uses: actions/checkout@v3 with: @@ -35,10 +35,10 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - name: Install rubocop 1.78.0 for Ruby 3.0.0 - if: matrix.ruby == '3.0.0' + - name: Install rubocop 1.78.0 for Ruby 3.0 + if: matrix.ruby == '3.0' run: | - echo "Installing rubocop 1.78.0 for Ruby 3.0.0" + echo "Installing rubocop 1.78.0 for Ruby 3.0" bundle add rubocop --version 1.78.0 || true bundle install bundle exec rubocop -A Gemfile || true From 4e2f54d5a631384aa16c7a1666cafdd5c082c668 Mon Sep 17 00:00:00 2001 From: esrakartalOpt Date: Fri, 20 Nov 2026 08:58:56 -0600 Subject: [PATCH 3/3] [FSSDK-13474] Keep MD5 for CMAB attributes fingerprint, document and suppress Revert the SHA256 change per review. The hash only detects changed attribute values in the local CMAB cache and is computed on every CMAB evaluation, so a fast non-cryptographic hash is preferable. Add a comment and nosemgrep suppression explaining that it is not used for security. Co-Authored-By: Claude Sonnet 5.5 --- lib/optimizely/cmab/cmab_service.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/optimizely/cmab/cmab_service.rb b/lib/optimizely/cmab/cmab_service.rb index 14706d53..71c3957a 100644 --- a/lib/optimizely/cmab/cmab_service.rb +++ b/lib/optimizely/cmab/cmab_service.rb @@ -205,16 +205,19 @@ def get_cache_key(user_id, rule_id) end def hash_attributes(attributes) - # Generates a SHA256 hash for a given attributes hash. + # Generates an MD5 hash for a given attributes hash. # # The method sorts the attributes by key, serializes them to a JSON string, - # and then computes the SHA256 hash of the resulting string. This ensures that + # and then computes the MD5 hash of the resulting string. This ensures that # the hash is consistent regardless of the original key order in the input hash. # # @param attributes [Hash] The attributes to be hashed. - # @return [String] The SHA256 hash of the sorted and serialized attributes. + # @return [String] The MD5 hash of the sorted and serialized attributes. sorted_attrs = JSON.generate(attributes.sort.to_h) - Digest::SHA256.hexdigest(sorted_attrs) + # MD5 is intentional: this is only a fast fingerprint to detect changed attribute values in the local + # CMAB cache (computed on every CMAB evaluation). It is not used for security, so a cryptographic hash is not needed. + # nosemgrep: ruby.lang.security.weak-hashes-md5.weak-hashes-md5 + Digest::MD5.hexdigest(sorted_attrs) end end end