diff --git a/core/modules/privacy/privacy.info.yml b/core/modules/privacy/privacy.info.yml new file mode 100644 index 0000000..3749027 --- /dev/null +++ b/core/modules/privacy/privacy.info.yml @@ -0,0 +1,4 @@ +name: Privacy +description: Provides various privacy enhancements +core: 8.x +type: module diff --git a/core/modules/privacy/privacy.module b/core/modules/privacy/privacy.module new file mode 100644 index 0000000..2d70b00 --- /dev/null +++ b/core/modules/privacy/privacy.module @@ -0,0 +1,21 @@ +' . t('About') . ''; + $output .= '

' . t('The privacy module removes some user specific information from the request, so modules cannot find something out about the users of the site.') . '

'; + + return $output; + } +} diff --git a/core/modules/privacy/privacy.services.yml b/core/modules/privacy/privacy.services.yml new file mode 100644 index 0000000..0562d58 --- /dev/null +++ b/core/modules/privacy/privacy.services.yml @@ -0,0 +1,5 @@ +services: + http_middleware.privacy: + class: \Drupal\privacy\StackMiddleware\PrivacyMiddleware + tags: + - { name: http_middleware, priority: 150, responder: true } diff --git a/core/modules/privacy/src/StackMiddleware/PrivacyMiddleware.php b/core/modules/privacy/src/StackMiddleware/PrivacyMiddleware.php new file mode 100644 index 0000000..f1c481d --- /dev/null +++ b/core/modules/privacy/src/StackMiddleware/PrivacyMiddleware.php @@ -0,0 +1,48 @@ +httpKernel = $httpKernel; + } + + /** + * {@inheritdoc} + */ + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) { + // @todo Decide which user agent we want to use. + $request->headers->set('user-agent', 'Mozilla/5.0'); + $request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0'); + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0'; + + // @todo ideally we would detect browser vs. not browser and then anonymize + // the accept header, accept-encoding and accept-language. + + $random_ip = implode(':', str_split(md5(mt_rand()), 4)); + $request->server->set('REMOTE_ADDR', $random_ip); + $_SERVER['REMOTE_ADDR'] = $random_ip; + return $this->httpKernel->handle($request, $type, $catch); + } + +}