From a4cf2e675f9db4c8dcb525ae4f909621ea2c7e73 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Sat, 16 May 2020 09:41:42 +1000 Subject: [PATCH] [DEPRECATE] Remove Google Analytics (#1021) * it doesn't work with our current CSP * it's probably not used by anyone * it isn't in harmony with our security purposes * literally removes all use of it * suggestions from code review * remove useless test. Co-authored-by: Amir Zarrinkafsh Co-authored-by: Clement Michaud --- config.template.yml | 5 -- docs/configuration/access-control.md | 2 +- docs/configuration/duo-push-notifications.md | 2 +- docs/configuration/google-analytics.md | 15 ----- docs/configuration/miscellaneous.md | 2 +- docs/configuration/one-time-password.md | 2 +- docs/configuration/regulation.md | 2 +- docs/configuration/secrets.md | 2 +- docs/configuration/server.md | 2 +- docs/configuration/session.md | 2 +- .../configuration/schema/configuration.go | 18 +++--- internal/configuration/validator/const.go | 10 ++-- internal/handlers/const.go | 1 - internal/handlers/handler_configuration.go | 10 ++-- .../handlers/handler_configuration_test.go | 30 ++-------- web/src/App.tsx | 57 +++++++++---------- web/src/components/Tracker.test.tsx | 11 ---- web/src/components/Tracker.tsx | 35 ------------ web/src/hooks/Tracking.tsx | 15 ----- web/src/models/Configuration.ts | 1 - 20 files changed, 55 insertions(+), 169 deletions(-) delete mode 100644 docs/configuration/google-analytics.md delete mode 100644 web/src/components/Tracker.test.tsx delete mode 100644 web/src/components/Tracker.tsx delete mode 100644 web/src/hooks/Tracking.tsx diff --git a/config.template.yml b/config.template.yml index 88291e46f..5c63e7158 100644 --- a/config.template.yml +++ b/config.template.yml @@ -39,11 +39,6 @@ jwt_secret: a_very_important_secret # be redirected upon successful authentication. default_redirection_url: https://home.example.com:8080/ -# Google Analytics Tracking ID to track the usage of the portal -# using a Google Analytics dashboard. -# -## google_analytics: UA-00000-01 - # TOTP Settings # # Parameters used for TOTP generation diff --git a/docs/configuration/access-control.md b/docs/configuration/access-control.md index 465b4b1bc..1de322eb5 100644 --- a/docs/configuration/access-control.md +++ b/docs/configuration/access-control.md @@ -2,7 +2,7 @@ layout: default title: Access Control parent: Configuration -nav_order: 2 +nav_order: 1 --- # Access Control diff --git a/docs/configuration/duo-push-notifications.md b/docs/configuration/duo-push-notifications.md index 207c3fee3..76bf39677 100644 --- a/docs/configuration/duo-push-notifications.md +++ b/docs/configuration/duo-push-notifications.md @@ -2,7 +2,7 @@ layout: default title: Duo Push Notifications parent: Configuration -nav_order: 3 +nav_order: 2 --- # Duo Push Notifications diff --git a/docs/configuration/google-analytics.md b/docs/configuration/google-analytics.md deleted file mode 100644 index f3b9e364c..000000000 --- a/docs/configuration/google-analytics.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -layout: default -title: Google Analytics -parent: Configuration -nav_order: 4 ---- - -# Google Analytics - -It is possible to provide a Google Analytics ID to Authelia in order -to monitor the usage of the Sign-In portal. - -```yaml -google_analytics: UA-00000-01 -``` \ No newline at end of file diff --git a/docs/configuration/miscellaneous.md b/docs/configuration/miscellaneous.md index 42acd2b00..8796a0a76 100644 --- a/docs/configuration/miscellaneous.md +++ b/docs/configuration/miscellaneous.md @@ -2,7 +2,7 @@ layout: default title: Miscellaneous parent: Configuration -nav_order: 5 +nav_order: 3 --- # Miscellaneous diff --git a/docs/configuration/one-time-password.md b/docs/configuration/one-time-password.md index 75b46059c..6818faacb 100644 --- a/docs/configuration/one-time-password.md +++ b/docs/configuration/one-time-password.md @@ -2,7 +2,7 @@ layout: default title: One-Time Password parent: Configuration -nav_order: 6 +nav_order: 4 --- # One-Time Password diff --git a/docs/configuration/regulation.md b/docs/configuration/regulation.md index 1d0a7fd21..e63b5371b 100644 --- a/docs/configuration/regulation.md +++ b/docs/configuration/regulation.md @@ -2,7 +2,7 @@ layout: default title: Regulation parent: Configuration -nav_order: 7 +nav_order: 5 --- # Regulation diff --git a/docs/configuration/secrets.md b/docs/configuration/secrets.md index 0b4ea99e6..b33e5b9dd 100644 --- a/docs/configuration/secrets.md +++ b/docs/configuration/secrets.md @@ -2,7 +2,7 @@ layout: default title: Secrets parent: Configuration -nav_order: 8 +nav_order: 6 --- # Secrets diff --git a/docs/configuration/server.md b/docs/configuration/server.md index 83dd38b3f..e984d8d09 100644 --- a/docs/configuration/server.md +++ b/docs/configuration/server.md @@ -2,7 +2,7 @@ layout: default title: Server parent: Configuration -nav_order: 9 +nav_order: 7 --- # Server diff --git a/docs/configuration/session.md b/docs/configuration/session.md index ac73b6751..d7e708867 100644 --- a/docs/configuration/session.md +++ b/docs/configuration/session.md @@ -2,7 +2,7 @@ layout: default title: Session parent: Configuration -nav_order: 10 +nav_order: 8 --- # Session diff --git a/internal/configuration/schema/configuration.go b/internal/configuration/schema/configuration.go index da6fc047d..8adad2e34 100644 --- a/internal/configuration/schema/configuration.go +++ b/internal/configuration/schema/configuration.go @@ -2,17 +2,15 @@ package schema // Configuration object extracted from YAML configuration file. type Configuration struct { - Host string `mapstructure:"host"` - Port int `mapstructure:"port"` - TLSCert string `mapstructure:"tls_cert"` - TLSKey string `mapstructure:"tls_key"` - LogLevel string `mapstructure:"log_level"` - LogFilePath string `mapstructure:"log_file_path"` - JWTSecret string `mapstructure:"jwt_secret"` - DefaultRedirectionURL string `mapstructure:"default_redirection_url"` - GoogleAnalyticsTrackingID string `mapstructure:"google_analytics"` + Host string `mapstructure:"host"` + Port int `mapstructure:"port"` + TLSCert string `mapstructure:"tls_cert"` + TLSKey string `mapstructure:"tls_key"` + LogLevel string `mapstructure:"log_level"` + LogFilePath string `mapstructure:"log_file_path"` + JWTSecret string `mapstructure:"jwt_secret"` + DefaultRedirectionURL string `mapstructure:"default_redirection_url"` - // TODO: Consider refactoring the following pointers as they don't seem to need to be pointers: TOTP, Notifier, Regulation AuthenticationBackend AuthenticationBackendConfiguration `mapstructure:"authentication_backend"` Session SessionConfiguration `mapstructure:"session"` TOTP *TOTPConfiguration `mapstructure:"totp"` diff --git a/internal/configuration/validator/const.go b/internal/configuration/validator/const.go index fab32e875..8874d9dcb 100644 --- a/internal/configuration/validator/const.go +++ b/internal/configuration/validator/const.go @@ -10,18 +10,17 @@ var validKeys = []string{ "jwt_secret", "tls_key", "tls_cert", - "google_analytics", // Server Keys. "server.read_buffer_size", "server.write_buffer_size", - // TOTP Keys + // TOTP Keys. "totp.issuer", "totp.period", "totp.skew", - // Access Control Keys + // Access Control Keys. "access_control.rules", "access_control.default_policy", @@ -130,8 +129,9 @@ var validKeys = []string{ } var specificErrorKeys = map[string]string{ - "logs_file_path": "config key replaced: logs_file is now log_file", - "logs_level": "config key replaced: logs_level is now log_level", + "logs_file_path": "config key replaced: logs_file is now log_file", + "logs_level": "config key replaced: logs_level is now log_level", + "google_analytics": "config key removed: google_analytics - this functionality has been deprecated", "authentication_backend.file.password_options.algorithm": "config key incorrect: authentication_backend.file.password_options should be authentication_backend.file.password", "authentication_backend.file.password_options.iterations": "config key incorrect: authentication_backend.file.password_options should be authentication_backend.file.password", "authentication_backend.file.password_options.key_length": "config key incorrect: authentication_backend.file.password_options should be authentication_backend.file.password", diff --git a/internal/handlers/const.go b/internal/handlers/const.go index f9e3b9172..137dabb80 100644 --- a/internal/handlers/const.go +++ b/internal/handlers/const.go @@ -35,7 +35,6 @@ const unableToRegisterSecurityKeyMessage = "Unable to register your security key const unableToResetPasswordMessage = "Unable to reset your password." const mfaValidationFailedMessage = "Authentication failed, please retry later." -const testGATrackingID = "ABC" const testInactivity = "10" const testRedirectionURL = "http://redirection.local" const testResultAllow = "allow" diff --git a/internal/handlers/handler_configuration.go b/internal/handlers/handler_configuration.go index c03653516..08d08dc79 100644 --- a/internal/handlers/handler_configuration.go +++ b/internal/handlers/handler_configuration.go @@ -4,17 +4,15 @@ import "github.com/authelia/authelia/internal/middlewares" // ConfigurationBody configuration parameters exposed to the frontend. type ConfigurationBody struct { - GoogleAnalyticsTrackingID string `json:"ga_tracking_id,omitempty"` - RememberMe bool `json:"remember_me"` // whether remember me is enabled or not - ResetPassword bool `json:"reset_password"` + RememberMe bool `json:"remember_me"` // whether remember me is enabled or not + ResetPassword bool `json:"reset_password"` } // ConfigurationGet fetches configuration parameters for frontend mutation. func ConfigurationGet(ctx *middlewares.AutheliaCtx) { body := ConfigurationBody{ - GoogleAnalyticsTrackingID: ctx.Configuration.GoogleAnalyticsTrackingID, - RememberMe: ctx.Providers.SessionProvider.RememberMe != 0, - ResetPassword: !ctx.Configuration.AuthenticationBackend.DisableResetPassword, + RememberMe: ctx.Providers.SessionProvider.RememberMe != 0, + ResetPassword: !ctx.Configuration.AuthenticationBackend.DisableResetPassword, } ctx.SetJSONBody(body) //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting. } diff --git a/internal/handlers/handler_configuration_test.go b/internal/handlers/handler_configuration_test.go index 6a9421c21..d1b64d400 100644 --- a/internal/handlers/handler_configuration_test.go +++ b/internal/handlers/handler_configuration_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/suite" - "github.com/authelia/authelia/internal/configuration/schema" "github.com/authelia/authelia/internal/mocks" "github.com/authelia/authelia/internal/session" ) @@ -24,31 +23,13 @@ func (s *ConfigurationSuite) TearDownTest() { s.mock.Close() } -func (s *ConfigurationSuite) TestShouldReturnConfiguredGATrackingID() { - GATrackingID := testGATrackingID - s.mock.Ctx.Configuration.GoogleAnalyticsTrackingID = GATrackingID - s.mock.Ctx.Configuration.Session.RememberMeDuration = schema.DefaultSessionConfiguration.RememberMeDuration - - expectedBody := ConfigurationBody{ - GoogleAnalyticsTrackingID: GATrackingID, - RememberMe: true, - ResetPassword: true, - } - - ConfigurationGet(s.mock.Ctx) - s.mock.Assert200OK(s.T(), expectedBody) -} - func (s *ConfigurationSuite) TestShouldDisableRememberMe() { - GATrackingID := testGATrackingID - s.mock.Ctx.Configuration.GoogleAnalyticsTrackingID = GATrackingID s.mock.Ctx.Configuration.Session.RememberMeDuration = "0" s.mock.Ctx.Providers.SessionProvider = session.NewProvider( s.mock.Ctx.Configuration.Session) expectedBody := ConfigurationBody{ - GoogleAnalyticsTrackingID: GATrackingID, - RememberMe: false, - ResetPassword: true, + RememberMe: false, + ResetPassword: true, } ConfigurationGet(s.mock.Ctx) @@ -56,13 +37,10 @@ func (s *ConfigurationSuite) TestShouldDisableRememberMe() { } func (s *ConfigurationSuite) TestShouldDisableResetPassword() { - GATrackingID := testGATrackingID - s.mock.Ctx.Configuration.GoogleAnalyticsTrackingID = GATrackingID s.mock.Ctx.Configuration.AuthenticationBackend.DisableResetPassword = true expectedBody := ConfigurationBody{ - GoogleAnalyticsTrackingID: GATrackingID, - RememberMe: true, - ResetPassword: false, + RememberMe: true, + ResetPassword: false, } ConfigurationGet(s.mock.Ctx) diff --git a/web/src/App.tsx b/web/src/App.tsx index 785e6e04c..fbba00f91 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -18,8 +18,6 @@ import { Notification } from './models/Notifications'; import NotificationBar from './components/NotificationBar'; import SignOut from './views/LoginPortal/SignOut/SignOut'; import { useConfiguration } from './hooks/Configuration'; -import Tracker from "./components/Tracker"; -import { useTracking } from "./hooks/Tracking"; import '@fortawesome/fontawesome-svg-core/styles.css' import {config as faConfig} from '@fortawesome/fontawesome-svg-core'; @@ -28,7 +26,6 @@ faConfig.autoAddCss = false; const App: React.FC = () => { const [notification, setNotification] = useState(null as Notification | null); const [configuration, fetchConfig, , fetchConfigError] = useConfiguration(); - const tracker = useTracking(configuration); useEffect(() => { if (fetchConfigError) { @@ -41,34 +38,32 @@ const App: React.FC = () => { return ( - - setNotification(null)} /> - - - - - - - - - - - - - - - - - - - - - - - - + setNotification(null)} /> + + + + + + + + + + + + + + + + + + + + + + + ); diff --git a/web/src/components/Tracker.test.tsx b/web/src/components/Tracker.test.tsx deleted file mode 100644 index 0ba960d7a..000000000 --- a/web/src/components/Tracker.test.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import React from 'react'; -import { mount } from "enzyme"; -import Tracker from "./Tracker"; - -import { MemoryRouter as Router } from 'react-router-dom'; - -const mountWithRouter = node => mount({node}); - -it('renders without crashing', () => { - mountWithRouter(); -}); \ No newline at end of file diff --git a/web/src/components/Tracker.tsx b/web/src/components/Tracker.tsx deleted file mode 100644 index a19840e1c..000000000 --- a/web/src/components/Tracker.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import React, { useEffect, useCallback, Fragment, ReactNode } from "react"; -import { useLocation } from "react-router"; -import ReactGA, { Tracker } from "react-ga"; - -export interface Props { - tracker: Tracker | undefined; - children?: ReactNode; -} - -export default function (props: Props) { - const location = useLocation(); - - const trackPage = useCallback((page: string) => { - if (props.tracker) { - ReactGA.set({ page }); - ReactGA.pageview(page); - } - }, [props.tracker]); - - useEffect(() => { - if (props.tracker) { - ReactGA.initialize([props.tracker]); - } - }, [props.tracker]); - - useEffect(() => { - trackPage(location.pathname + location.search); - }, [trackPage, location.pathname, location.search]); - - return ( - - {props.children} - - ) -} \ No newline at end of file diff --git a/web/src/hooks/Tracking.tsx b/web/src/hooks/Tracking.tsx deleted file mode 100644 index c6fe2815b..000000000 --- a/web/src/hooks/Tracking.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { useState, useEffect } from "react"; -import { Configuration } from "../models/Configuration"; -import { Tracker } from "react-ga"; - -export function useTracking(configuration: Configuration | undefined) { - const [trackingIds, setTrackingIds] = useState(undefined as Tracker | undefined); - - useEffect(() => { - if (configuration && configuration.ga_tracking_id) { - setTrackingIds({ trackingId: configuration.ga_tracking_id }); - } - }, [configuration]); - - return trackingIds; -} \ No newline at end of file diff --git a/web/src/models/Configuration.ts b/web/src/models/Configuration.ts index ab9bc123b..da022563a 100644 --- a/web/src/models/Configuration.ts +++ b/web/src/models/Configuration.ts @@ -1,7 +1,6 @@ import { SecondFactorMethod } from "./Methods"; export interface Configuration { - ga_tracking_id: string; remember_me: boolean; reset_password: boolean; }