Skip to content

Commit 7d21e04

Browse files
committed
server owner is unauthorized
1 parent 0bc7d70 commit 7d21e04

4 files changed

Lines changed: 120 additions & 0 deletions

File tree

dash/src/pages/api/server/[serverId]/guild-data.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,36 @@ export default async function handler(
1717
return res.status(400).json({ error: 'Invalid server ID' })
1818
}
1919

20+
// Check if user has access to this guild
21+
try {
22+
const guildsResponse = await fetch('https://discord.com/api/v10/users/@me/guilds', {
23+
headers: {
24+
Authorization: `Bearer ${(session as any).accessToken}`,
25+
},
26+
})
27+
28+
if (!guildsResponse.ok) {
29+
return res.status(401).json({ error: 'Failed to verify guild access' })
30+
}
31+
32+
const userGuilds = await guildsResponse.json()
33+
const guild = userGuilds.find((g: any) => g.id === serverId)
34+
35+
if (!guild) {
36+
return res.status(403).json({ error: 'You do not have access to this server' })
37+
}
38+
39+
// Check if user has MANAGE_GUILD permission (0x20 = 32) or is owner
40+
const hasPermission = guild.owner || (parseInt(guild.permissions) & 0x20) === 0x20
41+
42+
if (!hasPermission) {
43+
return res.status(403).json({ error: 'You do not have permission to manage this server' })
44+
}
45+
} catch (error) {
46+
console.error('Error checking guild permissions:', error)
47+
return res.status(500).json({ error: 'Failed to verify permissions' })
48+
}
49+
2050
try {
2151
// Fetch guild channels
2252
const channelsResponse = await fetch(

dash/src/pages/api/server/[serverId]/leaderboard.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,36 @@ export default async function handler(
4646
return res.status(400).json({ error: 'Invalid server ID' })
4747
}
4848

49+
// Check if user has access to this guild
50+
try {
51+
const guildsResponse = await fetch('https://discord.com/api/v10/users/@me/guilds', {
52+
headers: {
53+
Authorization: `Bearer ${(session as any).accessToken}`,
54+
},
55+
})
56+
57+
if (!guildsResponse.ok) {
58+
return res.status(401).json({ error: 'Failed to verify guild access' })
59+
}
60+
61+
const userGuilds = await guildsResponse.json()
62+
const guild = userGuilds.find((g: any) => g.id === serverId)
63+
64+
if (!guild) {
65+
return res.status(403).json({ error: 'You do not have access to this server' })
66+
}
67+
68+
// Check if user has MANAGE_GUILD permission (0x20 = 32) or is owner
69+
const hasPermission = guild.owner || (parseInt(guild.permissions) & 0x20) === 0x20
70+
71+
if (!hasPermission) {
72+
return res.status(403).json({ error: 'You do not have permission to manage this server' })
73+
}
74+
} catch (error) {
75+
console.error('Error checking guild permissions:', error)
76+
return res.status(500).json({ error: 'Failed to verify permissions' })
77+
}
78+
4979
try {
5080
// Fetch leaderboard from bot API with timeout
5181
const controller = new AbortController()

dash/src/pages/api/server/[serverId]/settings.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,36 @@ export default async function handler(
1919
return res.status(400).json({ error: 'Invalid server ID' })
2020
}
2121

22+
// Check if user has access to this guild
23+
try {
24+
const guildsResponse = await fetch('https://discord.com/api/v10/users/@me/guilds', {
25+
headers: {
26+
Authorization: `Bearer ${(session as any).accessToken}`,
27+
},
28+
})
29+
30+
if (!guildsResponse.ok) {
31+
return res.status(401).json({ error: 'Failed to verify guild access' })
32+
}
33+
34+
const userGuilds = await guildsResponse.json()
35+
const guild = userGuilds.find((g: any) => g.id === serverId)
36+
37+
if (!guild) {
38+
return res.status(403).json({ error: 'You do not have access to this server' })
39+
}
40+
41+
// Check if user has MANAGE_GUILD permission (0x20 = 32) or is owner
42+
const hasPermission = guild.owner || (parseInt(guild.permissions) & 0x20) === 0x20
43+
44+
if (!hasPermission) {
45+
return res.status(403).json({ error: 'You do not have permission to manage this server' })
46+
}
47+
} catch (error) {
48+
console.error('Error checking guild permissions:', error)
49+
return res.status(500).json({ error: 'Failed to verify permissions' })
50+
}
51+
2252
try {
2353
if (req.method === 'GET') {
2454
// Get guild settings from bot API

dash/src/pages/api/server/[serverId]/stats.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,36 @@ export default async function handler(
1919
return res.status(400).json({ error: 'Invalid server ID' })
2020
}
2121

22+
// Check if user has access to this guild
23+
try {
24+
const guildsResponse = await fetch('https://discord.com/api/v10/users/@me/guilds', {
25+
headers: {
26+
Authorization: `Bearer ${(session as any).accessToken}`,
27+
},
28+
})
29+
30+
if (!guildsResponse.ok) {
31+
return res.status(401).json({ error: 'Failed to verify guild access' })
32+
}
33+
34+
const userGuilds = await guildsResponse.json()
35+
const guild = userGuilds.find((g: any) => g.id === serverId)
36+
37+
if (!guild) {
38+
return res.status(403).json({ error: 'You do not have access to this server' })
39+
}
40+
41+
// Check if user has MANAGE_GUILD permission (0x20 = 32) or is owner
42+
const hasPermission = guild.owner || (parseInt(guild.permissions) & 0x20) === 0x20
43+
44+
if (!hasPermission) {
45+
return res.status(403).json({ error: 'You do not have permission to manage this server' })
46+
}
47+
} catch (error) {
48+
console.error('Error checking guild permissions:', error)
49+
return res.status(500).json({ error: 'Failed to verify permissions' })
50+
}
51+
2252
try {
2353
// Fetch stats from bot API with timeout
2454
const controller = new AbortController()

0 commit comments

Comments
 (0)