A free open source IT asset/license management system
Fixed 68gh-qwvc - license key log_meta search
snipe7ae0bea50d88
diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.phpindex 3c92ec3ad3..0ac7f7b360 100755--- a/app/Models/Actionlog.php+++ b/app/Models/Actionlog.php@@ -23,6 +23,7 @@ use Illuminate\Support\Str;* checkouts, checkins, and updates).** @version v1.0+ ** @mixin IdeHelperActionlog*/class Actionlog extends SnipeModel@@ -84,10 +85,18 @@ class Actionlog extends SnipeModel** @var array*/+ /*+ * 'log_meta' is intentionally not listed here. The column IS text-+ * searchable for every non-License row via advancedTextSearch() below,+ * which carries an explicit `item_type != License::class` guard. On+ * License rows log_meta carries the raw product-key diff and must+ * never be a search target, since the result-count differential+ * would otherwise be a timing oracle on the masked serial.+ * GHSA-68gh-qwvc-qccg.+ */protected $searchableAttributes = ['action_type','note',- 'log_meta','created_by','remote_ip','user_agent',@@ -119,7 +128,10 @@ class Actionlog extends SnipeModel'assets.location' => ['name'],'assets.defaultLoc' => ['name'],'assets.model.manufacturer' => ['name', 'notes'],- 'licenses' => ['name', 'serial', 'notes', 'license_email', 'license_name', 'purchase_order', 'purchase_date'],+ // 'serial' intentionally omitted: the activity-report search would+ // otherwise be a timing / result-count oracle on the real product+ // key for callers without licenses.keys. GHSA-68gh-qwvc-qccg.+ 'licenses' => ['name', 'notes', 'license_email', 'license_name', 'purchase_order', 'purchase_date'],'licenses.category' => ['name', 'notes'],'licenses.supplier' => ['name'],// consumables / components / accessories no longer expose a@@ -454,6 +466,23 @@ class Actionlog extends SnipeModel*/public function advancedTextSearch(Builder $query, array $terms){+ // log_meta is a JSON diff blob that admins legitimately search+ // across (who changed status to Lost, when the seat count moved),+ // so dropping it from search entirely is too destructive. On+ // License rows the same column carries the raw product-key diff+ // though, so matching log_meta there turns the result count into+ // a timing oracle on the masked serial. Scope the LIKE to+ // item_type != License to keep the admin workflows while shutting+ // the oracle. GHSA-68gh-qwvc-qccg.+ $query->orWhere(function (Builder $metaQuery) use ($terms): void {+ $metaQuery->where('action_logs.item_type', '!=', License::class)+ ->where(function (Builder $likeQuery) use ($terms): void {+ foreach ($terms as $term) {+ $likeQuery->orWhere('action_logs.log_meta', 'LIKE', '%'.$term.'%');+ }+ });+ });+return $query->orWhereHasMorph('target',[User::class, Asset::class, Location::class],diff --git a/tests/Feature/Licenses/LicenseSerialLeakTest.php b/tests/Feature/Licenses/LicenseSerialLeakTest.phpindex b32418c18c..9aa4172e8f 100644--- a/tests/Feature/Licenses/LicenseSerialLeakTest.php+++ b/tests/Feature/Licenses/LicenseSerialLeakTest.php@@ -3,6 +3,7 @@namespace Tests\Feature\Licenses;use App\Models\Actionlog;+use App\Models\Asset;use App\Models\License;use App\Models\LicenseSeat;use App\Models\User;@@ -78,6 +79,84 @@ class LicenseSerialLeakTest extends TestCase$this->assertStringNotContainsString(self::SENTINEL, $body);}+ public function test_activity_report_search_cannot_oracle_license_serial(): void+ {+ // Regression test for GHSA-68gh-qwvc-qccg. Before the fix,+ // GET /api/v1/reports/activity?item_type=license&item_id=X&search=<sub>+ // leaked the real product key one character at a time through+ // result-count differences on licenses.serial. The fix strips serial+ // from Actionlog::$searchableRelations['licenses'].+ $license = License::factory()->create(['name' => 'Adobe CC', 'serial' => self::SENTINEL]);+ LicenseSeat::factory()->for($license)->create();+ $this->seedCheckoutHistory($license);++ $viewOnly = User::factory()->canViewReports()->viewLicenses()->create();++ $bySerial = $this->actingAsForApi($viewOnly)+ ->getJson(route('api.activity.index', [+ 'item_type' => 'license',+ 'item_id' => $license->id,+ 'search' => 'SECRET-PRODUCT-KEY',+ ]))+ ->assertOk()+ ->json();+ $this->assertSame(0, $bySerial['total'], 'Activity report search must not expose license.serial as a text-search column, even for superusers.');++ // viewKeys does not re-open the hole. Unlike the license list, the+ // activity report has no legitimate caller for serial-substring+ // search, so the column is stripped unconditionally.+ $superuser = User::factory()->superuser()->create();+ $superuserBySerial = $this->actingAsForApi($superuser)+ ->getJson(route('api.activity.index', [+ 'item_type' => 'license',+ 'item_id' => $license->id,+ 'search' => 'SECRET-PRODUCT-KEY',+ ]))+ ->assertOk()+ ->json();+ $this->assertSame(0, $superuserBySerial['total']);++ // Search on a non-serial license column still works: proves we+ // haven't torched search for the licenses relation entirely.+ $byName = $this->actingAsForApi($superuser)+ ->getJson(route('api.activity.index', [+ 'item_type' => 'license',+ 'item_id' => $license->id,+ 'search' => 'Adobe',+ ]))+ ->assertOk()+ ->json();+ $this->assertGreaterThan(0, $byName['total']);+ }++ public function test_activity_report_search_still_matches_log_meta_on_non_license_rows(): void+ {+ // Companion assertion to the serial-oracle regression test above:+ // the fix removes log_meta from the trait-generic search path, but+ // re-adds it in advancedTextSearch() scoped to item_type != License.+ // That preserves "find who changed asset status to Lost" and+ // similar admin workflows on non-license logs.+ $asset = Asset::factory()->create();+ $log = new Actionlog;+ $log->item_type = Asset::class;+ $log->item_id = $asset->id;+ $log->action_type = 'update';+ $log->log_meta = json_encode([+ 'status_id' => ['old' => 'Ready to Deploy', 'new' => 'ARCHIVED-SENTINEL-STATUS'],+ ]);+ $log->save();++ $superuser = User::factory()->superuser()->create();++ $hit = $this->actingAsForApi($superuser)+ ->getJson(route('api.activity.index', [+ 'search' => 'ARCHIVED-SENTINEL-STATUS',+ ]))+ ->assertOk()+ ->json();+ $this->assertGreaterThan(0, $hit['total'], 'log_meta search must still match on non-license action logs after the oracle fix.');+ }+public function test_activity_report_api_masks_serial_for_users_without_view_keys(): void{$license = License::factory()->create(['serial' => self::SENTINEL]);