Repository navigation
fix(invite): route /invite through the backend and unify the permissions #1893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
cf383e3
fix(nginx): redirect /invite to discord at the edge
LucasSantana-Dev 834c453
fix(invite): route /invite through the backend and unify the permissions
LucasSantana-Dev 7c2c907
docs(nginx): explain why /invite does not use the internal directive
LucasSantana-Dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { describe, expect, it } from '@jest/globals' | ||
| import { | ||
| BOT_CLIENT_ID, | ||
| BOT_INVITE_PERMISSIONS, | ||
| buildBotInviteUrl, | ||
| } from './invite' | ||
|
|
||
| // Discord permission bits, for readable assertions. | ||
| const ADMINISTRATOR = 1n << 3n | ||
| const MANAGE_MESSAGES = 1n << 13n | ||
| const VIEW_CHANNEL = 1n << 10n | ||
| const SEND_MESSAGES = 1n << 11n | ||
| const EMBED_LINKS = 1n << 14n | ||
| const CONNECT = 1n << 20n | ||
| const SPEAK = 1n << 21n | ||
|
|
||
| describe('bot invite permissions', () => { | ||
| const bits = BigInt(BOT_INVITE_PERMISSIONS) | ||
|
|
||
| // The public listings state Lucky asks for no admin permission. Three | ||
| // copies of this value had already drifted: the docs page shipped | ||
| // Administrator and the backend redirect shipped Manage Messages (#1888, | ||
| // #1894), so this is a claim worth pinning rather than a style preference. | ||
| it('never requests Administrator', () => { | ||
| expect(bits & ADMINISTRATOR).toBe(0n) | ||
| }) | ||
|
|
||
| it('never requests Manage Messages', () => { | ||
| expect(bits & MANAGE_MESSAGES).toBe(0n) | ||
| }) | ||
|
|
||
| it('requests exactly the permissions the bot needs to function', () => { | ||
| const expected = | ||
| VIEW_CHANNEL | SEND_MESSAGES | EMBED_LINKS | CONNECT | SPEAK | ||
| expect(bits).toBe(expected) | ||
| }) | ||
| }) | ||
|
|
||
| describe('buildBotInviteUrl', () => { | ||
| it('targets the Discord OAuth endpoint with the shared permission set', () => { | ||
| expect(buildBotInviteUrl()).toBe( | ||
| `https://discord.com/oauth2/authorize?client_id=${BOT_CLIENT_ID}` + | ||
| `&scope=bot%20applications.commands&permissions=${BOT_INVITE_PERMISSIONS}`, | ||
| ) | ||
| }) | ||
|
|
||
| // Without applications.commands the bot joins but registers no slash | ||
| // commands, which is the shape of the failure that got the Top.gg | ||
| // verification rejected (#1885). | ||
| it('requests the applications.commands scope', () => { | ||
| expect(buildBotInviteUrl()).toContain( | ||
| 'scope=bot%20applications.commands', | ||
| ) | ||
| }) | ||
|
|
||
| it('accepts a fork client id', () => { | ||
| expect(buildBotInviteUrl('123')).toContain('client_id=123') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { TOP_GG_BOT_ID } from './topgg' | ||
|
|
||
| /** | ||
| * Minimal permission set for the bot invite: View Channels, Send Messages, | ||
| * Embed Links, Connect, Speak. | ||
| * | ||
| * NOT Administrator, and deliberately no Manage Messages. The public listings | ||
| * (Top.gg, README) state that Lucky only asks for what it needs, so this value | ||
| * is a promise we make to server admins, not a preference. | ||
| * | ||
| * This lives in shared because three copies had already drifted apart (#1888, | ||
| * #1894): the docs page shipped `8` (Administrator), the backend redirect | ||
| * shipped `36970496` (Manage Messages + Connect + Speak, and missing View | ||
| * Channels / Send Messages entirely), and only the landing page was correct. | ||
| */ | ||
| export const BOT_INVITE_PERMISSIONS = '3165184' | ||
|
|
||
| /** The Discord application id. Public: it appears in every OAuth invite URL. */ | ||
| export const BOT_CLIENT_ID = TOP_GG_BOT_ID | ||
|
|
||
| /** | ||
| * The canonical Discord OAuth invite URL. | ||
| * | ||
| * @param clientId - Override for forks running their own application. | ||
| */ | ||
| export function buildBotInviteUrl(clientId: string = BOT_CLIENT_ID): string { | ||
| return `https://discord.com/oauth2/authorize?client_id=${clientId}&scope=bot%20applications.commands&permissions=${BOT_INVITE_PERMISSIONS}` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.