Skip to content

Commit

Permalink
Remove Google FLoC
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Sep 20, 2023
1 parent 7b7da6e commit cdd57b0
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ repository:
name: NucleosGDPRBundle
description: ⚖️ This bundle provides a GDPR conform cookie information for symfony applications.
homepage: https://nucleos.rocks
topics: symfony, symfony-bundle, bundle, gdpr, dsgvo, sonata, sonata-block, blocker, floc, privacy
topics: symfony, symfony-bundle, bundle, gdpr, dsgvo, sonata, sonata-block, blocker, privacy
17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ This bundle provides a GDPR conform cookie information for symfony applications.

## Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
Open a command console, enter your project directory and execute the following command to download the latest stable
version of this bundle:

```
composer require nucleos/gdpr-bundle
Expand Down Expand Up @@ -59,20 +60,6 @@ nucleos_gdpr:
- ADMIN_.*
```


### Google FLoC (Federated Learning of Cohorts)

By default a `Permissions-Policy` header is added to every response to respect user privacy. You can enable Google FLoC tracking via the following configuration:

```yaml
# config/packages/nucleos_gdpr.yaml

nucleos_gdpr:
privacy:
google_floc: true
```


### Assets

It is recommended to use [webpack](https://webpack.js.org/) / [webpack-encore](https://github.com/symfony/webpack-encore)
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"block",
"widget",
"bundle",
"floc",
"privacy"
],
"authors": [
Expand Down
15 changes: 0 additions & 15 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function getConfigTreeBuilder(): TreeBuilder

$rootNode = $treeBuilder->getRootNode();
$rootNode->append($this->getBlockCookiesNode());
$rootNode->append($this->getPrivacyNode());

return $treeBuilder;
}
Expand All @@ -45,18 +44,4 @@ private function getBlockCookiesNode(): NodeDefinition

return $node;
}

private function getPrivacyNode(): NodeDefinition
{
$node = (new TreeBuilder('privacy'))->getRootNode();

$node
->addDefaultsIfNotSet()
->children()
->booleanNode('google_floc')->defaultFalse()->end()
->end()
;

return $node;
}
}
1 change: 0 additions & 1 deletion src/DependencyInjection/NucleosGDPRExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function load(array $configs, ContainerBuilder $container): void

$container->getDefinition(KernelEventSubscriber::class)
->replaceArgument(0, isset($config['block_cookies']) ? $config['block_cookies']['keep'] : null)
->replaceArgument(1, $config['privacy']['google_floc'])
;
}
}
16 changes: 1 addition & 15 deletions src/EventListener/KernelEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,19 @@ final class KernelEventSubscriber implements EventSubscriberInterface
*/
private ?array $whitelist;

private bool $googleFLOC;

/**
* @param string[] $whitelist
*/
public function __construct(?array $whitelist = [], bool $googleFLOC = false)
public function __construct(?array $whitelist = [])
{
$this->whitelist = $whitelist;
$this->googleFLOC = $googleFLOC;
}

public static function getSubscribedEvents(): array
{
return [
KernelEvents::RESPONSE => [
['cleanCookies', 0],
['addFLoCPolicy', 0],
],
];
}
Expand Down Expand Up @@ -70,16 +66,6 @@ public function cleanCookies(ResponseEvent $event): void
}
}

public function addFLoCPolicy(ResponseEvent $event): void
{
if (true === $this->googleFLOC) {
return;
}

$response = $event->getResponse();
$response->headers->set('Permissions-Policy', 'interest-cohort=()');
}

/**
* @param Cookie[] $cookies
*/
Expand Down
28 changes: 0 additions & 28 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,6 @@ public function testDefaultOptions(): void
$config = $processor->processConfiguration(new Configuration(), []);

$expected = [
'privacy' => [
'google_floc' => false,
],
];

static::assertSame($expected, $config);
}

public function testEnabledGoogleFLoC(): void
{
$processor = new Processor();

$config = $processor->processConfiguration(new Configuration(), [[
'privacy' => [
'google_floc' => true,
],
]]);

$expected = [
'privacy' => [
'google_floc' => true,
],
];

static::assertSame($expected, $config);
Expand All @@ -63,9 +41,6 @@ public function testBlockedCookieEnabled(): void
'block_cookies' => [
'keep' => ['PHPSESSID'],
],
'privacy' => [
'google_floc' => false,
],
];

static::assertSame($expected, $config);
Expand All @@ -85,9 +60,6 @@ public function testBlockedCookieOptions(): void
'block_cookies' => [
'keep' => ['SOMEKEY', 'OTHERKEY'],
],
'privacy' => [
'google_floc' => false,
],
];

static::assertSame($expected, $config);
Expand Down
11 changes: 0 additions & 11 deletions tests/DependencyInjection/NucleosGDPRExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ public function testLoadWithCookieBlock(): void
]);
}

public function testLoadWithGoogleFLoC(): void
{
$this->load([
'privacy' => [
'google_floc' => true,
],
]);

$this->assertContainerBuilderHasServiceDefinitionWithArgument(KernelEventSubscriber::class, 1, true);
}

protected function getContainerExtensions(): array
{
return [
Expand Down
35 changes: 0 additions & 35 deletions tests/EventListener/KernelEventSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,41 +105,6 @@ public function testCleanCookiesWithNoConsent(): void
$this->assertHasCookie(self::KEEP_REGED_EXAMPLE, $response);
}

public function testAddFLoCPolicy(): void
{
$response = new Response();

$event = new ResponseEvent(
$this->createStub(HttpKernelInterface::class),
$this->createStub(Request::class),
0,
$response
);

$subscriber = new KernelEventSubscriber(null, false);
$subscriber->addFLoCPolicy($event);

static::assertTrue($response->headers->has('Permissions-Policy'));
static::assertSame('interest-cohort=()', $response->headers->get('Permissions-Policy'));
}

public function testAddFLoCPolicyWithDisabledOption(): void
{
$response = new Response();

$event = new ResponseEvent(
$this->createStub(HttpKernelInterface::class),
$this->createStub(Request::class),
0,
$response
);

$subscriber = new KernelEventSubscriber(null, true);
$subscriber->addFLoCPolicy($event);

static::assertFalse($response->headers->has('Permissions-Policy'));
}

private function assertHasCookie(string $cookieName, Response $response): void
{
static::assertCount(1, array_filter($response->headers->getCookies(), static function (Cookie $cookie) use ($cookieName): bool {
Expand Down

0 comments on commit cdd57b0

Please sign in to comment.