fix: use page origin for website_data_access permission, not requesting domain
- commit
- 784ca95ed33f61f55823cd170ba77fc589708ea3
- author
- brice · · 2026-03-25 12:35 UTC
- parent
- 2f35bdf
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +8 -21
M internal/application/usecase/handle_permission_test.go +7 -7
| @@ -542,7 +542,7 @@ func TestHandlePermissionUseCase_WebsiteDataAccess_ShowsDialogAndPersists(t *tes | |||
| 542 | 542 | uc := usecase.NewHandlePermissionUseCase(permRepo, dialog, permissionLoggerFromContext) | |
| 543 | 543 | ||
| 544 | 544 | // No stored permission | |
| 545 | - | permRepo.EXPECT().Get(mock.Anything, "https://accounts.google.com", entity.PermissionTypeWebsiteDataAccess). | |
| 545 | + | permRepo.EXPECT().Get(mock.Anything, "https://shop.example.com", entity.PermissionTypeWebsiteDataAccess). | |
| 546 | 546 | Return(nil, nil) | |
| 547 | 547 | ||
| 548 | 548 | allowed := false | |
| @@ -554,7 +554,7 @@ func TestHandlePermissionUseCase_WebsiteDataAccess_ShowsDialogAndPersists(t *tes | |||
| 554 | 554 | // Dialog shows and user clicks "Always Allow" | |
| 555 | 555 | dialog.EXPECT().ShowPermissionDialog( | |
| 556 | 556 | mock.Anything, | |
| 557 | - | "https://accounts.google.com", | |
| 557 | + | "https://shop.example.com", | |
| 558 | 558 | []entity.PermissionType{entity.PermissionTypeWebsiteDataAccess}, | |
| 559 | 559 | mock.Anything, | |
| 560 | 560 | ).Run(func(_ context.Context, _ string, _ []entity.PermissionType, cb func(port.PermissionDialogResult)) { | |
| @@ -564,12 +564,12 @@ func TestHandlePermissionUseCase_WebsiteDataAccess_ShowsDialogAndPersists(t *tes | |||
| 564 | 564 | // Should persist the granted permission | |
| 565 | 565 | permRepo.EXPECT().Set(mock.Anything, mock.AnythingOfType("*entity.PermissionRecord")). | |
| 566 | 566 | Run(func(_ context.Context, r *entity.PermissionRecord) { | |
| 567 | - | assert.Equal(t, "https://accounts.google.com", r.Origin) | |
| 567 | + | assert.Equal(t, "https://shop.example.com", r.Origin) | |
| 568 | 568 | assert.Equal(t, entity.PermissionTypeWebsiteDataAccess, r.Type) | |
| 569 | 569 | assert.Equal(t, entity.PermissionGranted, r.Decision) | |
| 570 | 570 | }).Return(nil) | |
| 571 | 571 | ||
| 572 | - | uc.HandlePermissionRequest(ctx, "https://accounts.google.com", []entity.PermissionType{ | |
| 572 | + | uc.HandlePermissionRequest(ctx, "https://shop.example.com", []entity.PermissionType{ | |
| 573 | 573 | entity.PermissionTypeWebsiteDataAccess, | |
| 574 | 574 | }, callback) | |
| 575 | 575 | ||
| @@ -584,9 +584,9 @@ func TestHandlePermissionUseCase_WebsiteDataAccess_UsesStoredGrant(t *testing.T) | |||
| 584 | 584 | uc := usecase.NewHandlePermissionUseCase(permRepo, dialog, permissionLoggerFromContext) | |
| 585 | 585 | ||
| 586 | 586 | // Stored granted permission | |
| 587 | - | permRepo.EXPECT().Get(mock.Anything, "https://accounts.google.com", entity.PermissionTypeWebsiteDataAccess). | |
| 587 | + | permRepo.EXPECT().Get(mock.Anything, "https://shop.example.com", entity.PermissionTypeWebsiteDataAccess). | |
| 588 | 588 | Return(&entity.PermissionRecord{ | |
| 589 | - | Origin: "https://accounts.google.com", | |
| 589 | + | Origin: "https://shop.example.com", | |
| 590 | 590 | Type: entity.PermissionTypeWebsiteDataAccess, | |
| 591 | 591 | Decision: entity.PermissionGranted, | |
| 592 | 592 | }, nil) | |
| @@ -597,7 +597,7 @@ func TestHandlePermissionUseCase_WebsiteDataAccess_UsesStoredGrant(t *testing.T) | |||
| 597 | 597 | Deny: func() {}, | |
| 598 | 598 | } | |
| 599 | 599 | ||
| 600 | - | uc.HandlePermissionRequest(ctx, "https://accounts.google.com", []entity.PermissionType{ | |
| 600 | + | uc.HandlePermissionRequest(ctx, "https://shop.example.com", []entity.PermissionType{ | |
| 601 | 601 | entity.PermissionTypeWebsiteDataAccess, | |
| 602 | 602 | }, callback) | |
| 603 | 603 | ||
| @@ -542,7 +542,7 @@ func TestHandlePermissionUseCase_WebsiteDataAccess_ShowsDialogAndPersists(t *tes | |||||
| 542 | uc := usecase.NewHandlePermissionUseCase(permRepo, dialog, permissionLoggerFromContext) | 542 | uc := usecase.NewHandlePermissionUseCase(permRepo, dialog, permissionLoggerFromContext) | ||
| 543 | 543 | ||||
| 544 | // No stored permission | 544 | // No stored permission | ||
| 545 | - | permRepo.EXPECT().Get(mock.Anything, "https://accounts.google.com", entity.PermissionTypeWebsiteDataAccess). | 545 | + | permRepo.EXPECT().Get(mock.Anything, "https://shop.example.com", entity.PermissionTypeWebsiteDataAccess). |
| 546 | Return(nil, nil) | 546 | Return(nil, nil) | ||
| 547 | 547 | ||||
| 548 | allowed := false | 548 | allowed := false | ||
| @@ -554,7 +554,7 @@ func TestHandlePermissionUseCase_WebsiteDataAccess_ShowsDialogAndPersists(t *tes | |||||
| 554 | // Dialog shows and user clicks "Always Allow" | 554 | // Dialog shows and user clicks "Always Allow" | ||
| 555 | dialog.EXPECT().ShowPermissionDialog( | 555 | dialog.EXPECT().ShowPermissionDialog( | ||
| 556 | mock.Anything, | 556 | mock.Anything, | ||
| 557 | - | "https://accounts.google.com", | 557 | + | "https://shop.example.com", |
| 558 | []entity.PermissionType{entity.PermissionTypeWebsiteDataAccess}, | 558 | []entity.PermissionType{entity.PermissionTypeWebsiteDataAccess}, | ||
| 559 | mock.Anything, | 559 | mock.Anything, | ||
| 560 | ).Run(func(_ context.Context, _ string, _ []entity.PermissionType, cb func(port.PermissionDialogResult)) { | 560 | ).Run(func(_ context.Context, _ string, _ []entity.PermissionType, cb func(port.PermissionDialogResult)) { | ||
| @@ -564,12 +564,12 @@ func TestHandlePermissionUseCase_WebsiteDataAccess_ShowsDialogAndPersists(t *tes | |||||
| 564 | // Should persist the granted permission | 564 | // Should persist the granted permission | ||
| 565 | permRepo.EXPECT().Set(mock.Anything, mock.AnythingOfType("*entity.PermissionRecord")). | 565 | permRepo.EXPECT().Set(mock.Anything, mock.AnythingOfType("*entity.PermissionRecord")). | ||
| 566 | Run(func(_ context.Context, r *entity.PermissionRecord) { | 566 | Run(func(_ context.Context, r *entity.PermissionRecord) { | ||
| 567 | - | assert.Equal(t, "https://accounts.google.com", r.Origin) | 567 | + | assert.Equal(t, "https://shop.example.com", r.Origin) |
| 568 | assert.Equal(t, entity.PermissionTypeWebsiteDataAccess, r.Type) | 568 | assert.Equal(t, entity.PermissionTypeWebsiteDataAccess, r.Type) | ||
| 569 | assert.Equal(t, entity.PermissionGranted, r.Decision) | 569 | assert.Equal(t, entity.PermissionGranted, r.Decision) | ||
| 570 | }).Return(nil) | 570 | }).Return(nil) | ||
| 571 | 571 | ||||
| 572 | - | uc.HandlePermissionRequest(ctx, "https://accounts.google.com", []entity.PermissionType{ | 572 | + | uc.HandlePermissionRequest(ctx, "https://shop.example.com", []entity.PermissionType{ |
| 573 | entity.PermissionTypeWebsiteDataAccess, | 573 | entity.PermissionTypeWebsiteDataAccess, | ||
| 574 | }, callback) | 574 | }, callback) | ||
| 575 | 575 | ||||
| @@ -584,9 +584,9 @@ func TestHandlePermissionUseCase_WebsiteDataAccess_UsesStoredGrant(t *testing.T) | |||||
| 584 | uc := usecase.NewHandlePermissionUseCase(permRepo, dialog, permissionLoggerFromContext) | 584 | uc := usecase.NewHandlePermissionUseCase(permRepo, dialog, permissionLoggerFromContext) | ||
| 585 | 585 | ||||
| 586 | // Stored granted permission | 586 | // Stored granted permission | ||
| 587 | - | permRepo.EXPECT().Get(mock.Anything, "https://accounts.google.com", entity.PermissionTypeWebsiteDataAccess). | 587 | + | permRepo.EXPECT().Get(mock.Anything, "https://shop.example.com", entity.PermissionTypeWebsiteDataAccess). |
| 588 | Return(&entity.PermissionRecord{ | 588 | Return(&entity.PermissionRecord{ | ||
| 589 | - | Origin: "https://accounts.google.com", | 589 | + | Origin: "https://shop.example.com", |
| 590 | Type: entity.PermissionTypeWebsiteDataAccess, | 590 | Type: entity.PermissionTypeWebsiteDataAccess, | ||
| 591 | Decision: entity.PermissionGranted, | 591 | Decision: entity.PermissionGranted, | ||
| 592 | }, nil) | 592 | }, nil) | ||
| @@ -597,7 +597,7 @@ func TestHandlePermissionUseCase_WebsiteDataAccess_UsesStoredGrant(t *testing.T) | |||||
| 597 | Deny: func() {}, | 597 | Deny: func() {}, | ||
| 598 | } | 598 | } | ||
| 599 | 599 | ||||
| 600 | - | uc.HandlePermissionRequest(ctx, "https://accounts.google.com", []entity.PermissionType{ | 600 | + | uc.HandlePermissionRequest(ctx, "https://shop.example.com", []entity.PermissionType{ |
| 601 | entity.PermissionTypeWebsiteDataAccess, | 601 | entity.PermissionTypeWebsiteDataAccess, | ||
| 602 | }, callback) | 602 | }, callback) | ||
| 603 | 603 | ||||
M internal/infrastructure/webkit/webview.go +1 -14
| @@ -1086,20 +1086,7 @@ func (wv *WebView) determinePermissionTypes(ctx context.Context, requestPtr uint | |||
| 1086 | 1086 | Str("current_domain", currentDomain). | |
| 1087 | 1087 | Str("requesting_domain", requestingDomain). | |
| 1088 | 1088 | Msg("website data access permission request") | |
| 1089 | - | override := "" | |
| 1090 | - | if requestingDomain != "" { | |
| 1091 | - | candidate := "https://" + requestingDomain | |
| 1092 | - | if normalized, err := urlutil.ExtractOrigin(candidate); err == nil { | |
| 1093 | - | override = normalized | |
| 1094 | - | } else { | |
| 1095 | - | wv.logger.Warn(). | |
| 1096 | - | Str("requesting_domain", requestingDomain). | |
| 1097 | - | Err(err). | |
| 1098 | - | Msg("website data access: failed to normalize requesting domain, using raw") | |
| 1099 | - | override = candidate | |
| 1100 | - | } | |
| 1101 | - | } | |
| 1102 | - | return classifyPermissionRequestTypes(ctx, requestKind, false, false, false), override | |
| 1089 | + | return classifyPermissionRequestTypes(ctx, requestKind, false, false, false), "" | |
| 1103 | 1090 | default: | |
| 1104 | 1091 | if requestPtr != 0 { | |
| 1105 | 1092 | typeName := permissionRequestTypeName(ctx, requestPtr) | |
| @@ -1086,20 +1086,7 @@ func (wv *WebView) determinePermissionTypes(ctx context.Context, requestPtr uint | |||||
| 1086 | Str("current_domain", currentDomain). | 1086 | Str("current_domain", currentDomain). | ||
| 1087 | Str("requesting_domain", requestingDomain). | 1087 | Str("requesting_domain", requestingDomain). | ||
| 1088 | Msg("website data access permission request") | 1088 | Msg("website data access permission request") | ||
| 1089 | - | override := "" | 1089 | + | return classifyPermissionRequestTypes(ctx, requestKind, false, false, false), "" |
| 1090 | - | if requestingDomain != "" { | |||
| 1091 | - | candidate := "https://" + requestingDomain | |||
| 1092 | - | if normalized, err := urlutil.ExtractOrigin(candidate); err == nil { | |||
| 1093 | - | override = normalized | |||
| 1094 | - | } else { | |||
| 1095 | - | wv.logger.Warn(). | |||
| 1096 | - | Str("requesting_domain", requestingDomain). | |||
| 1097 | - | Err(err). | |||
| 1098 | - | Msg("website data access: failed to normalize requesting domain, using raw") | |||
| 1099 | - | override = candidate | |||
| 1100 | - | } | |||
| 1101 | - | } | |||
| 1102 | - | return classifyPermissionRequestTypes(ctx, requestKind, false, false, false), override | |||
| 1103 | default: | 1090 | default: | ||
| 1104 | if requestPtr != 0 { | 1091 | if requestPtr != 0 { | ||
| 1105 | typeName := permissionRequestTypeName(ctx, requestPtr) | 1092 | typeName := permissionRequestTypeName(ctx, requestPtr) | ||