Verified Commit 0f4c82b7 authored by catch's avatar catch Committed by Jess
Browse files

task: #3633176 Add test coverage for SA-CORE-2026-004

By: xjm
By: bbrala
By: benjifisher
By: catch
By: longwave
By: larowlan
By: mcdruid
(cherry picked from commit 600ed8e3)
parent 5f407d2c
Loading
Loading
Loading
Loading
Loading
+52 −0
Changes for core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php: 52 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1189,6 +1189,58 @@ public function testCaseSensitivity(): void {

  }

  /**
   * Tests that array keys cannot inject SQL.
   */
  public function testCaseInsensitiveInWithAssociativeArrayKeys(): void {
    $bundle = $this->randomMachineName();
    EntityTestHelper::createBundle($bundle, entity_type: 'entity_test_mulrev');

    $field_storage = FieldStorageConfig::create([
      'field_name' => 'field_ci',
      'entity_type' => 'entity_test_mulrev',
      'type' => 'string',
      'cardinality' => 1,
      'translatable' => FALSE,
      'settings' => [
        'case_sensitive' => FALSE,
      ],
    ]);
    $field_storage->save();

    FieldConfig::create([
      'field_storage' => $field_storage,
      'bundle' => $bundle,
    ])->save();

    $entity = EntityTestMulRev::create([
      'type' => $bundle,
      'name' => $this->randomMachineName(),
      'langcode' => 'en',
      'field_ci' => 'Needle',
    ]);
    $entity->save();

    $result = $this->storage
      ->getQuery()
      ->accessCheck(FALSE)
      ->condition('field_ci', [
        "evil) OR 1=1 --" => 'needle',
        "x'); DROP TABLE {entity_test_mulrev} --" => 'NEEDLE',
      ], 'IN')
      ->execute();
    $this->assertCount(1, $result);
    $this->assertSame([(string) $entity->getRevisionId() => (string) $entity->id()], $result);

    // Verify the table still exists.
    $second = $this->storage
      ->getQuery()
      ->accessCheck(FALSE)
      ->condition('field_ci', ['needle'], 'IN')
      ->execute();
    $this->assertCount(1, $second);
  }

  /**
   * Tests base fields with multiple columns.
   */