Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Coder
code-server
提交
2086648c
C
code-server
项目概览
镜像
/
Coder
/
code-server
2022-09-21 03:15:05同步失败
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2086648c
编写于
3月 23, 2020
作者:
A
Asher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Only handle exact domain matches
This simplifies the logic a bit.
上级
3a98d856
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
36 deletion
+32
-36
src/node/app/proxy.ts
src/node/app/proxy.ts
+23
-16
src/node/http.ts
src/node/http.ts
+9
-20
未找到文件。
src/node/app/proxy.ts
浏览文件 @
2086648c
...
@@ -6,8 +6,15 @@ import { HttpProvider, HttpProviderOptions, HttpProxyProvider, HttpResponse, Rou
...
@@ -6,8 +6,15 @@ import { HttpProvider, HttpProviderOptions, HttpProxyProvider, HttpResponse, Rou
* Proxy HTTP provider.
* Proxy HTTP provider.
*/
*/
export
class
ProxyHttpProvider
extends
HttpProvider
implements
HttpProxyProvider
{
export
class
ProxyHttpProvider
extends
HttpProvider
implements
HttpProxyProvider
{
/**
* Proxy domains are stored here without the leading `*.`
*/
public
readonly
proxyDomains
:
string
[]
public
readonly
proxyDomains
:
string
[]
/**
* Domains can be provided in the form `coder.com` or `*.coder.com`. Either
* way, `<number>.coder.com` will be proxied to `number`.
*/
public
constructor
(
options
:
HttpProviderOptions
,
proxyDomains
:
string
[]
=
[])
{
public
constructor
(
options
:
HttpProviderOptions
,
proxyDomains
:
string
[]
=
[])
{
super
(
options
)
super
(
options
)
this
.
proxyDomains
=
proxyDomains
.
map
((
d
)
=>
d
.
replace
(
/^
\*\.
/
,
""
)).
filter
((
d
,
i
,
arr
)
=>
arr
.
indexOf
(
d
)
===
i
)
this
.
proxyDomains
=
proxyDomains
.
map
((
d
)
=>
d
.
replace
(
/^
\*\.
/
,
""
)).
filter
((
d
,
i
,
arr
)
=>
arr
.
indexOf
(
d
)
===
i
)
...
@@ -29,12 +36,14 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
...
@@ -29,12 +36,14 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
throw
new
HttpError
(
"
Not found
"
,
HttpCode
.
NotFound
)
throw
new
HttpError
(
"
Not found
"
,
HttpCode
.
NotFound
)
}
}
public
getProxyDomain
(
host
?:
string
):
string
|
undefined
{
public
getCookieDomain
(
host
:
string
):
string
{
if
(
!
host
||
!
this
.
proxyDomains
)
{
let
current
:
string
|
undefined
return
undefined
this
.
proxyDomains
.
forEach
((
domain
)
=>
{
}
if
(
host
.
endsWith
(
domain
)
&&
(
!
current
||
domain
.
length
<
current
.
length
))
{
current
=
domain
return
this
.
proxyDomains
.
find
((
d
)
=>
host
.
endsWith
(
d
))
}
})
return
current
||
host
}
}
public
maybeProxy
(
request
:
http
.
IncomingMessage
):
HttpResponse
|
undefined
{
public
maybeProxy
(
request
:
http
.
IncomingMessage
):
HttpResponse
|
undefined
{
...
@@ -44,23 +53,21 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
...
@@ -44,23 +53,21 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
return
undefined
return
undefined
}
}
// At minimum there needs to be sub.domain.tld.
const
host
=
request
.
headers
.
host
const
host
=
request
.
headers
.
host
const
p
roxyDomain
=
this
.
getProxyDomain
(
host
)
const
p
arts
=
host
&&
host
.
split
(
"
.
"
)
if
(
!
host
||
!
proxyDomain
)
{
if
(
!
parts
||
parts
.
length
<
3
)
{
return
undefined
return
undefined
}
}
const
proxyDomainLength
=
proxyDomain
.
split
(
"
.
"
).
length
// There must be an exact match.
const
portStr
=
host
const
port
=
parts
.
shift
()
.
split
(
"
.
"
)
const
proxyDomain
=
parts
.
join
(
"
.
"
)
.
slice
(
0
,
-
proxyDomainLength
)
if
(
!
port
||
!
this
.
proxyDomains
.
includes
(
proxyDomain
))
{
.
pop
()
if
(
!
portStr
)
{
return
undefined
return
undefined
}
}
return
this
.
proxy
(
port
Str
)
return
this
.
proxy
(
port
)
}
}
private
proxy
(
portStr
:
string
):
HttpResponse
{
private
proxy
(
portStr
:
string
):
HttpResponse
{
...
...
src/node/http.ts
浏览文件 @
2086648c
...
@@ -397,27 +397,20 @@ export interface HttpProvider3<A1, A2, A3, T> {
...
@@ -397,27 +397,20 @@ export interface HttpProvider3<A1, A2, A3, T> {
export
interface
HttpProxyProvider
{
export
interface
HttpProxyProvider
{
/**
/**
* Return a response if the request should be proxied. Anything that ends in a
* Return a response if the request should be proxied. Anything that ends in a
* proxy domain and has a
subdomain should be proxied. The port is found in
* proxy domain and has a
*single* subdomain should be proxied. Anything else
*
the top-most subdomain
.
*
should return `undefined` and will be handled as normal
.
*
*
* For example, if the proxy domain is `coder.com` then `8080.coder.com` and
* For example if `coder.com` is specified `8080.coder.com` will be proxied
* `test.8080.coder.com` will both proxy to `8080` but `8080.test.coder.com`
* but `8080.test.coder.com` and `test.8080.coder.com` will not.
* will have an error because `test` isn't a port. If the proxy domain was
* `test.coder.com` then it would work.
*/
*/
maybeProxy
(
request
:
http
.
IncomingMessage
):
HttpResponse
|
undefined
maybeProxy
(
request
:
http
.
IncomingMessage
):
HttpResponse
|
undefined
/**
/**
* Get the matching proxy domain based on the provided host.
* Get the domain that should be used for setting a cookie. This will allow
* the user to authenticate only once. This will return the highest level
* domain (e.g. `coder.com` over `test.coder.com` if both are specified).
*/
*/
getProxyDomain
(
host
:
string
):
string
|
undefined
getCookieDomain
(
host
:
string
):
string
|
undefined
/**
* Domains can be provided in the form `coder.com` or `*.coder.com`. Either
* way, `<number>.coder.com` will be proxied to `number`. The domains are
* stored here without the `*.`.
*/
readonly
proxyDomains
:
string
[]
}
}
/**
/**
...
@@ -560,12 +553,8 @@ export class HttpServer {
...
@@ -560,12 +553,8 @@ export class HttpServer {
"
Set-Cookie
"
:
[
"
Set-Cookie
"
:
[
`
${
payload
.
cookie
.
key
}
=
${
payload
.
cookie
.
value
}
`
,
`
${
payload
.
cookie
.
key
}
=
${
payload
.
cookie
.
value
}
`
,
`Path=
${
normalize
(
payload
.
cookie
.
path
||
"
/
"
,
true
)}
`
,
`Path=
${
normalize
(
payload
.
cookie
.
path
||
"
/
"
,
true
)}
`
,
// Set the cookie against the host so it can be used in
// subdomains. Use a matching proxy domain if possible so
// requests to any of those subdomains will already be
// authenticated.
request
.
headers
.
host
request
.
headers
.
host
?
`Domain=
${(
this
.
proxy
&&
this
.
proxy
.
get
Proxy
Domain
(
request
.
headers
.
host
))
||
request
.
headers
.
host
}
`
?
`Domain=
${(
this
.
proxy
&&
this
.
proxy
.
get
Cookie
Domain
(
request
.
headers
.
host
))
||
request
.
headers
.
host
}
`
:
undefined
,
:
undefined
,
// "HttpOnly",
// "HttpOnly",
"
SameSite=strict
"
,
"
SameSite=strict
"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录