1
1
// @ts -check
2
- const schemes = new Set ( [ 'vscode' , 'vscode-insiders' , 'vscodium' , 'gitpod-code' , 'code-oss' ] )
3
- const validQueryParams = new Set ( [ 'vscode-reqid' , 'vscode-scheme' , 'vscode-authority' , 'vscode-path' , 'windowId' ] )
2
+ let schemes = new Set ( [
3
+ 'vscode' ,
4
+ 'vscode-insiders' ,
5
+ 'vscodium' ,
6
+ 'gitpod-code' ,
7
+ 'code-oss' ,
8
+ ] )
9
+ let validQueryParams = new Set ( [
10
+ 'vscode-reqid' ,
11
+ 'vscode-scheme' ,
12
+ 'vscode-authority' ,
13
+ 'vscode-path' ,
14
+ 'windowId' ,
15
+ ] )
4
16
5
17
/**
6
18
* @param {import('@netlify/functions').HandlerEvent } event
@@ -12,7 +24,12 @@ exports.handler = async function (event, _context) {
12
24
if ( state == null ) throw new Error ( `Missing "state" query parameter.` )
13
25
const url = new URL ( Buffer . from ( state , 'base64url' ) . toString ( ) )
14
26
const scheme = url . protocol . slice ( 0 , - 1 )
15
- if ( scheme === 'http' || scheme === 'https' ) {
27
+ if (
28
+ url . host === 'https://github.dev' &&
29
+ url . pathname === '/extension-auth-callback'
30
+ ) {
31
+ validQueryParams = new Set ( [ 'state' ] )
32
+ } else if ( scheme === 'http' || scheme === 'https' ) {
16
33
validate (
17
34
url . searchParams . get ( 'vscode-scheme' ) ,
18
35
url . searchParams . get ( 'vscode-authority' ) ,
@@ -22,20 +39,20 @@ exports.handler = async function (event, _context) {
22
39
validate ( scheme , url . host , url . pathname )
23
40
}
24
41
42
+ url . searchParams . set ( 'code' , code )
25
43
url . searchParams . forEach ( ( _ , key ) => {
26
44
if ( ! validQueryParams . has ( key ) ) url . searchParams . delete ( key )
27
45
} )
28
46
29
- url . searchParams . set ( 'code' , code )
30
- url . searchParams . set ( 'state' , '' )
31
-
32
47
return getResponse ( url . toString ( ) )
33
48
}
34
49
35
50
function validate ( scheme , hostname , pathname ) {
36
51
if ( ! schemes . has ( scheme ) ) throw new Error ( `Invalid scheme: ${ scheme } ` )
37
- if ( hostname !== 'znck.grammarly' ) throw new Error ( `Invalid authority: ${ hostname } ` )
38
- if ( pathname !== '/auth/callback' ) throw new Error ( `Invalid path: ${ pathname } ` )
52
+ if ( hostname !== 'znck.grammarly' )
53
+ throw new Error ( `Invalid authority: ${ hostname } ` )
54
+ if ( pathname !== '/auth/callback' )
55
+ throw new Error ( `Invalid path: ${ pathname } ` )
39
56
}
40
57
41
58
/**
0 commit comments