Skip to content

Commit 1ec567b

Browse files
committed
feat: disallow running spicetify as admin/root
1 parent 37fa210 commit 1ec567b

File tree

2 files changed

+65
-16
lines changed

2 files changed

+65
-16
lines changed

CustomApps/lyrics-plus/index.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@ const CONFIG = {
5858
delay: 0,
5959
},
6060
providers: {
61+
lrclib: {
62+
on: getConfig("lyrics-plus:provider:lrclib:on"),
63+
desc: "Lyrics sourced from lrclib.net. Supports both synced and unsynced lyrics. LRCLIB is a free and open-source lyrics provider.",
64+
modes: [SYNCED, UNSYNCED],
65+
},
6166
musixmatch: {
6267
on: getConfig("lyrics-plus:provider:musixmatch:on"),
63-
desc: "Fully compatible with Spotify. Requires a token that can be retrieved from the official Musixmatch app. If you have problems with retrieving lyrics, try refreshing the token by clicking <code>Refresh Token</code> button.",
68+
desc: "Fully compatible with Spotify. Requires a token that can be retrieved from the official Musixmatch app. If you have problems with retrieving lyrics, try refreshing the token by clicking <code>Refresh Token</code> button. You may need to be forced to use your own CORS Proxy to use this provider.",
6469
token: localStorage.getItem("lyrics-plus:provider:musixmatch:token") || "21051986b9886beabe1ce01c3ce94c96319411f8f2c122676365e3",
6570
modes: [KARAOKE, SYNCED, UNSYNCED],
6671
},
@@ -70,15 +75,10 @@ const CONFIG = {
7075
modes: [SYNCED, UNSYNCED],
7176
},
7277
netease: {
73-
on: getConfig("lyrics-plus:provider:netease:on"),
78+
on: getConfig("lyrics-plus:provider:netease:on", false),
7479
desc: "Crowdsourced lyrics provider ran by Chinese developers and users.",
7580
modes: [KARAOKE, SYNCED, UNSYNCED],
7681
},
77-
lrclib: {
78-
on: getConfig("lyrics-plus:provider:lrclib:on"),
79-
desc: "Lyrics sourced from lrclib.net. Supports both synced and unsynced lyrics. LRCLIB is a free and open-source lyrics provider.",
80-
modes: [SYNCED, UNSYNCED],
81-
},
8282
genius: {
8383
on: spotifyVersion >= "1.2.31" ? false : getConfig("lyrics-plus:provider:genius:on"),
8484
desc: "Provide unsynced lyrics with insights from artists themselves. Genius is disabled and cannot be used as a provider on <code>1.2.31</code> and higher.",
@@ -175,9 +175,10 @@ class LyricsContainer extends react.Component {
175175
this.styleVariables = {};
176176
this.fullscreenContainer = document.createElement("div");
177177
this.fullscreenContainer.id = "lyrics-fullscreen-container";
178-
this.mousetrap = new Spicetify.Mousetrap();
178+
this.mousetrap = null;
179179
this.containerRef = react.createRef(null);
180180
this.translator = null;
181+
this.initMoustrap();
181182
// Cache last state
182183
this.languageOverride = CONFIG.visual["translate:detect-language-override"];
183184
this.translate = CONFIG.visual.translate;
@@ -647,6 +648,11 @@ class LyricsContainer extends react.Component {
647648
reader.readAsText(file[0]);
648649
event.target.value = "";
649650
}
651+
initMoustrap() {
652+
if (!this.mousetrap && Spicetify.Mousetrap) {
653+
this.mousetrap = new Spicetify.Mousetrap();
654+
}
655+
}
650656

651657
componentDidMount() {
652658
this.onQueueChange = async ({ data: queue }) => {

spicetify.go

+51-8
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,55 @@ import (
1717
"github.com/spicetify/cli/src/cmd"
1818
spotifystatus "github.com/spicetify/cli/src/status/spotify"
1919
"github.com/spicetify/cli/src/utils"
20+
"golang.org/x/sys/windows"
2021
)
2122

2223
var (
2324
version string
2425
)
2526

2627
var (
27-
flags = []string{}
28-
commands = []string{}
29-
quiet = false
30-
extensionFocus = false
31-
appFocus = false
32-
styleFocus = false
33-
noRestart = false
34-
liveRefresh = false
28+
flags = []string{}
29+
commands = []string{}
30+
quiet = false
31+
extensionFocus = false
32+
appFocus = false
33+
styleFocus = false
34+
noRestart = false
35+
liveRefresh = false
36+
bypassAdminCheck = false
3537
)
3638

39+
func isAdmin(bypassAdminCheck bool) bool {
40+
if bypassAdminCheck {
41+
return false
42+
}
43+
44+
switch runtime.GOOS {
45+
case "windows":
46+
var sid *windows.SID
47+
err := windows.AllocateAndInitializeSid(
48+
&windows.SECURITY_NT_AUTHORITY,
49+
2,
50+
windows.SECURITY_BUILTIN_DOMAIN_RID,
51+
windows.DOMAIN_ALIAS_RID_ADMINS,
52+
0, 0, 0, 0, 0, 0,
53+
&sid)
54+
if err != nil {
55+
return false
56+
}
57+
defer windows.FreeSid(sid)
58+
59+
token := windows.Token(0)
60+
member, err := token.IsMember(sid)
61+
return err == nil && member
62+
63+
case "linux", "darwin":
64+
return os.Geteuid() == 0
65+
}
66+
return false
67+
}
68+
3769
func init() {
3870
if runtime.GOOS != "windows" &&
3971
runtime.GOOS != "darwin" &&
@@ -66,6 +98,8 @@ func init() {
6698

6799
for _, v := range flags {
68100
switch v {
101+
case "--bypass-admin":
102+
bypassAdminCheck = true
69103
case "-c", "--config":
70104
fmt.Println(cmd.GetConfigPath())
71105
os.Exit(0)
@@ -110,6 +144,15 @@ func init() {
110144
os.Stdout = nil
111145
}
112146

147+
if isAdmin(bypassAdminCheck) {
148+
utils.PrintError("Spicetify should not be run with administrator/root privileges")
149+
utils.PrintError("Running as admin can cause Spotify to show a black/blank window after applying spicetify")
150+
utils.PrintError("This happens because Spotify (running as a normal user) can't access files modified with admin privileges")
151+
utils.PrintInfo("If you understand the risks and need to continue anyway, you can use the '--bypass-admin' flag.")
152+
utils.PrintInfo("Spicetify is now exiting...")
153+
os.Exit(1)
154+
}
155+
113156
utils.MigrateConfigFolder()
114157
utils.MigrateFolders()
115158
cmd.InitConfig(quiet)

0 commit comments

Comments
 (0)