1
1
// Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the MIT License. See License.txt in the project root for license information.
3
3
4
- using System . Collections . Generic ;
5
4
using Microsoft . AspNetCore . Authentication . JwtBearer ;
6
5
using Microsoft . AspNetCore . Authorization ;
7
6
using Microsoft . AspNetCore . Http ;
8
7
using Microsoft . AspNetCore . Mvc . Filters ;
9
- using Microsoft . AspNetCore . Routing ;
10
8
using Microsoft . Azure . WebJobs . Extensions . Http ;
11
9
using Microsoft . Azure . WebJobs . Script . Extensions ;
12
10
using Microsoft . Azure . WebJobs . Script . WebHost . Authentication ;
@@ -22,6 +20,18 @@ public static void AddScriptPolicies(this AuthorizationOptions options)
22
20
{
23
21
p . AddScriptAuthenticationSchemes ( ) ;
24
22
p . AddRequirements ( new AuthLevelRequirement ( AuthorizationLevel . Admin ) ) ;
23
+ p . RequireAssertion ( c =>
24
+ {
25
+ if ( c . Resource is AuthorizationFilterContext filterContext )
26
+ {
27
+ if ( ! CheckPlatformInternal ( filterContext . HttpContext , allowAppServiceInternal : false ) )
28
+ {
29
+ return false ;
30
+ }
31
+ }
32
+
33
+ return true ;
34
+ } ) ;
25
35
} ) ;
26
36
27
37
options . AddPolicy ( PolicyNames . SystemAuthLevel , p =>
@@ -37,6 +47,11 @@ public static void AddScriptPolicies(this AuthorizationOptions options)
37
47
{
38
48
if ( c . Resource is AuthorizationFilterContext filterContext )
39
49
{
50
+ if ( ! CheckPlatformInternal ( filterContext . HttpContext , allowAppServiceInternal : true ) )
51
+ {
52
+ return false ;
53
+ }
54
+
40
55
if ( filterContext . HttpContext . Request . IsAppServiceInternalRequest ( ) )
41
56
{
42
57
return true ;
@@ -96,5 +111,20 @@ private static void AddScriptAuthenticationSchemes(this AuthorizationPolicyBuild
96
111
builder . AuthenticationSchemes . Add ( AuthLevelAuthenticationDefaults . AuthenticationScheme ) ;
97
112
builder . AuthenticationSchemes . Add ( JwtBearerDefaults . AuthenticationScheme ) ;
98
113
}
114
+
115
+ internal static bool CheckPlatformInternal ( HttpContext httpContext , bool allowAppServiceInternal )
116
+ {
117
+ // when AdminIsolation is enabled, verify the request is platform internal
118
+ var environment = httpContext . RequestServices . GetRequiredService < IEnvironment > ( ) ;
119
+ if ( environment . IsAdminIsolationEnabled ( ) &&
120
+ ! ( httpContext . Request . IsPlatformInternalRequest ( environment ) || ( allowAppServiceInternal && httpContext . Request . IsAppServiceInternalRequest ( ) ) ) )
121
+ {
122
+ // request must either be granted PlatformInternal by FrontEnd, or must be an internal
123
+ // request that has bypassed FrontEnd
124
+ return false ;
125
+ }
126
+
127
+ return true ;
128
+ }
99
129
}
100
130
}
0 commit comments