🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Don't expose Last.fm API Key in the index.html
Deluan1f71e5674111
diff --git a/server/auth.go b/server/auth.goindex 44cc94fdd..2d7c6b68b 100644--- a/server/auth.go+++ b/server/auth.go@@ -77,6 +77,9 @@ func buildAuthPayload(user *model.User) map[string]interface{} {if conf.Server.EnableGravatar && user.Email != "" {payload["avatar"] = gravatar.Url(user.Email, 50)}+ if conf.Server.LastFM.Enabled {+ payload["lastFMApiKey"] = conf.Server.LastFM.ApiKey+ }bytes := make([]byte, 3)_, err := rand.Read(bytes)diff --git a/server/serve_index.go b/server/serve_index.goindex cb4271b4e..5cfb35f75 100644--- a/server/serve_index.go+++ b/server/serve_index.go@@ -60,8 +60,7 @@ func serveIndex(ds model.DataStore, fs fs.FS, shareInfo *model.Share) http.Handl"enableSharing": conf.Server.EnableSharing,"defaultDownloadableShare": conf.Server.DefaultDownloadableShare,"devSidebarPlaylists": conf.Server.DevSidebarPlaylists,- "lastFMEnabled": conf.Server.LastFM.Enabled,- "lastFMApiKey": conf.Server.LastFM.ApiKey,+ "lastFMEnabled": conf.Server.LastFM.Enabled && conf.Server.LastFM.ApiKey != "" && conf.Server.LastFM.Secret != "","devShowArtistPage": conf.Server.DevShowArtistPage,"listenBrainzEnabled": conf.Server.ListenBrainz.Enabled,"enableExternalServices": conf.Server.EnableExternalServices,diff --git a/server/serve_index_test.go b/server/serve_index_test.goindex 01f36a79e..c03e02592 100644--- a/server/serve_index_test.go+++ b/server/serve_index_test.go@@ -281,24 +281,17 @@ var _ = Describe("serveIndex", func() {})It("sets the lastFMEnabled", func() {- r := httptest.NewRequest("GET", "/index.html", nil)- w := httptest.NewRecorder()+ conf.Server.LastFM.Enabled = true+ conf.Server.LastFM.ApiKey = "123"+ conf.Server.LastFM.Secret = "456"- serveIndex(ds, fs, nil)(w, r)-- config := extractAppConfig(w.Body.String())- Expect(config).To(HaveKeyWithValue("lastFMEnabled", true))- })-- It("sets the lastFMApiKey", func() {- conf.Server.LastFM.ApiKey = "APIKEY-123"r := httptest.NewRequest("GET", "/index.html", nil)w := httptest.NewRecorder()serveIndex(ds, fs, nil)(w, r)config := extractAppConfig(w.Body.String())- Expect(config).To(HaveKeyWithValue("lastFMApiKey", "APIKEY-123"))+ Expect(config).To(HaveKeyWithValue("lastFMEnabled", true))})It("sets the devShowArtistPage", func() {diff --git a/ui/src/authProvider.js b/ui/src/authProvider.jsindex c22e9345d..ac510c2cd 100644--- a/ui/src/authProvider.js+++ b/ui/src/authProvider.js@@ -21,6 +21,7 @@ function storeAuthenticationInfo(authInfo) {localStorage.setItem('role', authInfo.isAdmin ? 'admin' : 'regular')localStorage.setItem('subsonic-salt', authInfo.subsonicSalt)localStorage.setItem('subsonic-token', authInfo.subsonicToken)+ localStorage.setItem('lastfm-apikey', authInfo.lastFMApiKey)localStorage.setItem('is-authenticated', 'true')}@@ -102,6 +103,7 @@ const removeItems = () => {localStorage.removeItem('role')localStorage.removeItem('subsonic-salt')localStorage.removeItem('subsonic-token')+ localStorage.removeItem('lastfm-apikey')localStorage.removeItem('is-authenticated')}diff --git a/ui/src/config.js b/ui/src/config.jsindex 7548ab134..f2281fac2 100644--- a/ui/src/config.js+++ b/ui/src/config.js@@ -25,7 +25,6 @@ const defaultConfig = {defaultDownloadableShare: true,devSidebarPlaylists: true,lastFMEnabled: true,- lastFMApiKey: '9b94a5515ea66b2da3ec03c12300327e',listenBrainzEnabled: true,enableExternalServices: true,enableCoverAnimation: true,diff --git a/ui/src/personal/LastfmScrobbleToggle.js b/ui/src/personal/LastfmScrobbleToggle.jsindex 84532de36..ec0fddbbf 100644--- a/ui/src/personal/LastfmScrobbleToggle.js+++ b/ui/src/personal/LastfmScrobbleToggle.js@@ -7,7 +7,6 @@ import {Switch,} from '@material-ui/core'import { useInterval } from '../common'-import config from '../config'import { baseUrl, openInNewTab } from '../utils'import { httpClient } from '../dataProvider'@@ -24,7 +23,7 @@ const Progress = (props) => {)const callbackUrl = `${window.location.origin}${callbackEndpoint}`openedTab.current = openInNewTab(- `https://www.last.fm/api/auth/?api_key=${config.lastFMApiKey}&cb=${callbackUrl}`,+ `https://www.last.fm/api/auth/?api_key=${localStorage.getItem('lastfm-apikey')}&cb=${callbackUrl}`,)}, [])