Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
73d9d76e
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
73d9d76e
编写于
11月 06, 2019
作者:
P
Pine Wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #83731
上级
e88e032d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
74 addition
and
34 deletion
+74
-34
src/vs/workbench/contrib/url/common/trustedDomainsFileSystemProvider.ts
...ch/contrib/url/common/trustedDomainsFileSystemProvider.ts
+2
-0
src/vs/workbench/contrib/url/common/trustedDomainsValidator.ts
...s/workbench/contrib/url/common/trustedDomainsValidator.ts
+28
-8
src/vs/workbench/test/contrib/linkProtection.test.ts
src/vs/workbench/test/contrib/linkProtection.test.ts
+44
-26
未找到文件。
src/vs/workbench/contrib/url/common/trustedDomainsFileSystemProvider.ts
浏览文件 @
73d9d76e
...
...
@@ -26,6 +26,8 @@ const TRUSTED_DOMAINS_STAT: IStat = {
const
CONFIG_HELP_TEXT_PRE
=
`// Links matching one or more entries in the list below can be opened without link protection.
// The following examples show what entries can look like:
// - "https://microsoft.com": Matches this specific domain using https
// - "https://microsoft.com/foo": Matches https://microsoft.com/foo and https://microsoft.com/foo/bar,
// but not https://microsoft.com/foobar or https://microsoft.com/bar
// - "https://*.microsoft.com": Match all domains ending in "microsoft.com" using https
// - "microsoft.com": Match this specific domain using either http or https
// - "*.microsoft.com": Match all domains ending in "microsoft.com" using either http or https
...
...
src/vs/workbench/contrib/url/common/trustedDomainsValidator.ts
浏览文件 @
73d9d76e
...
...
@@ -5,7 +5,7 @@
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
Severity
from
'
vs/base/common/severity
'
;
import
{
equalsIgnoreCase
}
from
'
vs/base/common/strings
'
;
import
{
equalsIgnoreCase
,
startsWith
}
from
'
vs/base/common/strings
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
IDialogService
}
from
'
vs/platform/dialogs/common/dialogs
'
;
...
...
@@ -14,7 +14,10 @@ import { IProductService } from 'vs/platform/product/common/productService';
import
{
IQuickInputService
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
IStorageService
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IWorkbenchContribution
}
from
'
vs/workbench/common/contributions
'
;
import
{
configureOpenerTrustedDomainsHandler
,
readTrustedDomains
}
from
'
vs/workbench/contrib/url/common/trustedDomains
'
;
import
{
configureOpenerTrustedDomainsHandler
,
readTrustedDomains
}
from
'
vs/workbench/contrib/url/common/trustedDomains
'
;
import
{
IEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
export
class
OpenerValidatorContributions
implements
IWorkbenchContribution
{
...
...
@@ -132,10 +135,11 @@ export function isURLDomainTrusted(url: URI, trustedDomains: string[]) {
}
if
(
url
.
authority
===
parsedTrustedDomain
.
authority
)
{
return
true
;
return
pathMatches
(
url
.
path
,
parsedTrustedDomain
.
path
)
;
}
if
(
trustedDomains
[
i
].
indexOf
(
'
*
'
)
!==
-
1
)
{
let
reversedAuthoritySegments
=
url
.
authority
.
split
(
'
.
'
).
reverse
();
const
reversedTrustedDomainAuthoritySegments
=
parsedTrustedDomain
.
authority
.
split
(
'
.
'
).
reverse
();
...
...
@@ -146,11 +150,11 @@ export function isURLDomainTrusted(url: URI, trustedDomains: string[]) {
reversedAuthoritySegments
=
reversedAuthoritySegments
.
slice
(
0
,
reversedTrustedDomainAuthoritySegments
.
length
);
}
if
(
re
versedAuthoritySegments
.
every
((
val
,
i
)
=>
{
return
reversedTrustedDomainAuthoritySegments
[
i
]
===
'
*
'
||
val
===
reversedTrustedDomainAuthoritySegments
[
i
]
;
})
)
{
const
authorityMatches
=
reversedAuthoritySegments
.
every
((
val
,
i
)
=>
{
re
turn
reversedTrustedDomainAuthoritySegments
[
i
]
===
'
*
'
||
val
===
reversedTrustedDomainAuthoritySegments
[
i
];
})
;
if
(
authorityMatches
&&
pathMatches
(
url
.
path
,
parsedTrustedDomain
.
path
)
)
{
return
true
;
}
}
...
...
@@ -158,3 +162,19 @@ export function isURLDomainTrusted(url: URI, trustedDomains: string[]) {
return
false
;
}
function
pathMatches
(
open
:
string
,
rule
:
string
)
{
if
(
rule
===
'
/
'
)
{
return
true
;
}
const
openSegments
=
open
.
split
(
'
/
'
);
const
ruleSegments
=
rule
.
split
(
'
/
'
);
for
(
let
i
=
0
;
i
<
ruleSegments
.
length
;
i
++
)
{
if
(
ruleSegments
[
i
]
!==
openSegments
[
i
])
{
return
false
;
}
}
return
true
;
}
src/vs/workbench/test/contrib/linkProtection.test.ts
浏览文件 @
73d9d76e
...
...
@@ -8,49 +8,67 @@ import * as assert from 'assert';
import
{
isURLDomainTrusted
}
from
'
vs/workbench/contrib/url/common/trustedDomainsValidator
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
function
link
Protect
edByRules
(
link
:
string
,
rules
:
string
[])
{
assert
.
ok
(
isURLDomainTrusted
(
URI
.
parse
(
link
),
rules
));
function
link
Allow
edByRules
(
link
:
string
,
rules
:
string
[])
{
assert
.
ok
(
isURLDomainTrusted
(
URI
.
parse
(
link
),
rules
)
,
`Link\n
${
link
}
\n should be protected by rules\n
${
JSON
.
stringify
(
rules
)}
`
);
}
function
linkNot
Protect
edByRules
(
link
:
string
,
rules
:
string
[])
{
assert
.
ok
(
!
isURLDomainTrusted
(
URI
.
parse
(
link
),
rules
));
function
linkNot
Allow
edByRules
(
link
:
string
,
rules
:
string
[])
{
assert
.
ok
(
!
isURLDomainTrusted
(
URI
.
parse
(
link
),
rules
)
,
`Link\n
${
link
}
\n should NOT be protected by rules\n
${
JSON
.
stringify
(
rules
)}
`
);
}
suite
(
'
Link protection domain matching
'
,
()
=>
{
test
(
'
simple
'
,
()
=>
{
linkNot
Protect
edByRules
(
'
https://x.org
'
,
[]);
linkNot
Allow
edByRules
(
'
https://x.org
'
,
[]);
link
Protect
edByRules
(
'
https://x.org
'
,
[
'
https://x.org
'
]);
link
Protect
edByRules
(
'
https://x.org/foo
'
,
[
'
https://x.org
'
]);
link
Allow
edByRules
(
'
https://x.org
'
,
[
'
https://x.org
'
]);
link
Allow
edByRules
(
'
https://x.org/foo
'
,
[
'
https://x.org
'
]);
linkNot
Protect
edByRules
(
'
https://x.org
'
,
[
'
http://x.org
'
]);
linkNot
Protect
edByRules
(
'
http://x.org
'
,
[
'
https://x.org
'
]);
linkNot
Allow
edByRules
(
'
https://x.org
'
,
[
'
http://x.org
'
]);
linkNot
Allow
edByRules
(
'
http://x.org
'
,
[
'
https://x.org
'
]);
linkNot
Protect
edByRules
(
'
https://www.x.org
'
,
[
'
https://x.org
'
]);
linkNot
Allow
edByRules
(
'
https://www.x.org
'
,
[
'
https://x.org
'
]);
link
Protect
edByRules
(
'
https://www.x.org
'
,
[
'
https://www.x.org
'
,
'
https://y.org
'
]);
link
Allow
edByRules
(
'
https://www.x.org
'
,
[
'
https://www.x.org
'
,
'
https://y.org
'
]);
});
test
(
'
localhost
'
,
()
=>
{
link
Protect
edByRules
(
'
https://127.0.0.1
'
,
[]);
link
Protect
edByRules
(
'
https://127.0.0.1:3000
'
,
[]);
link
Protect
edByRules
(
'
https://localhost
'
,
[]);
link
Protect
edByRules
(
'
https://localhost:3000
'
,
[]);
link
Allow
edByRules
(
'
https://127.0.0.1
'
,
[]);
link
Allow
edByRules
(
'
https://127.0.0.1:3000
'
,
[]);
link
Allow
edByRules
(
'
https://localhost
'
,
[]);
link
Allow
edByRules
(
'
https://localhost:3000
'
,
[]);
});
test
(
'
* star
'
,
()
=>
{
link
Protect
edByRules
(
'
https://a.x.org
'
,
[
'
https://*.x.org
'
]);
link
Protect
edByRules
(
'
https://a.b.x.org
'
,
[
'
https://*.x.org
'
]);
link
Protect
edByRules
(
'
https://a.x.org
'
,
[
'
https://a.x.*
'
]);
link
Protect
edByRules
(
'
https://a.x.org
'
,
[
'
https://a.*.org
'
]);
link
Protect
edByRules
(
'
https://a.x.org
'
,
[
'
https://*.*.org
'
]);
link
Protect
edByRules
(
'
https://a.b.x.org
'
,
[
'
https://*.b.*.org
'
]);
link
Protect
edByRules
(
'
https://a.a.b.x.org
'
,
[
'
https://*.b.*.org
'
]);
link
Allow
edByRules
(
'
https://a.x.org
'
,
[
'
https://*.x.org
'
]);
link
Allow
edByRules
(
'
https://a.b.x.org
'
,
[
'
https://*.x.org
'
]);
link
Allow
edByRules
(
'
https://a.x.org
'
,
[
'
https://a.x.*
'
]);
link
Allow
edByRules
(
'
https://a.x.org
'
,
[
'
https://a.*.org
'
]);
link
Allow
edByRules
(
'
https://a.x.org
'
,
[
'
https://*.*.org
'
]);
link
Allow
edByRules
(
'
https://a.b.x.org
'
,
[
'
https://*.b.*.org
'
]);
link
Allow
edByRules
(
'
https://a.a.b.x.org
'
,
[
'
https://*.b.*.org
'
]);
});
test
(
'
no scheme
'
,
()
=>
{
linkProtectedByRules
(
'
https://a.x.org
'
,
[
'
a.x.org
'
]);
linkProtectedByRules
(
'
https://a.x.org
'
,
[
'
*.x.org
'
]);
linkProtectedByRules
(
'
https://a.b.x.org
'
,
[
'
*.x.org
'
]);
linkProtectedByRules
(
'
https://x.org
'
,
[
'
*.x.org
'
]);
linkAllowedByRules
(
'
https://a.x.org
'
,
[
'
a.x.org
'
]);
linkAllowedByRules
(
'
https://a.x.org
'
,
[
'
*.x.org
'
]);
linkAllowedByRules
(
'
https://a.b.x.org
'
,
[
'
*.x.org
'
]);
linkAllowedByRules
(
'
https://x.org
'
,
[
'
*.x.org
'
]);
});
test
(
'
sub paths
'
,
()
=>
{
linkAllowedByRules
(
'
https://x.org/foo
'
,
[
'
https://x.org/foo
'
]);
linkAllowedByRules
(
'
https://x.org/foo
'
,
[
'
x.org/foo
'
]);
linkAllowedByRules
(
'
https://x.org/foo
'
,
[
'
*.org/foo
'
]);
linkNotAllowedByRules
(
'
https://x.org/bar
'
,
[
'
https://x.org/foo
'
]);
linkNotAllowedByRules
(
'
https://x.org/bar
'
,
[
'
x.org/foo
'
]);
linkNotAllowedByRules
(
'
https://x.org/bar
'
,
[
'
*.org/foo
'
]);
linkAllowedByRules
(
'
https://x.org/foo/bar
'
,
[
'
https://x.org/foo
'
]);
linkNotAllowedByRules
(
'
https://x.org/foo2
'
,
[
'
https://x.org/foo
'
]);
linkNotAllowedByRules
(
'
https://www.x.org/foo
'
,
[
'
https://x.org/foo
'
]);
linkNotAllowedByRules
(
'
https://a.x.org/bar
'
,
[
'
https://*.x.org/foo
'
]);
linkNotAllowedByRules
(
'
https://a.b.x.org/bar
'
,
[
'
https://*.x.org/foo
'
]);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录