11// Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
4- using System . Collections . Generic ;
4+ using System ;
55using System . Linq ;
66using System . Reflection ;
77using Microsoft . AspNetCore . Mvc ;
8+ using Microsoft . AspNetCore . Mvc . Routing ;
89using Microsoft . Azure . WebJobs . Script . WebHost ;
910using Microsoft . Azure . WebJobs . Script . WebHost . Controllers ;
1011using Microsoft . Azure . WebJobs . Script . WebHost . Filters ;
@@ -39,6 +40,7 @@ public void VerifyHostReadApis()
3940 "FunctionsController.GetFunctionStatus" ,
4041 "FunctionsController.List" ,
4142 "HostController.DrainStatus" ,
43+ "HostController.ExtensionWebHookHandler" ,
4244 "HostController.GetConfig" ,
4345 "HostController.GetHostStatus" ,
4446 "HostController.GetWorkerProcesses" ,
@@ -49,12 +51,33 @@ public void VerifyHostReadApis()
4951
5052 // looking for all GET actions that aren't marked with the ResourceContainsSecretsAttribute
5153 var methodInfos = typeof ( HostController ) . Assembly . GetTypes ( ) . Where ( p => typeof ( Controller ) . IsAssignableFrom ( p ) ) . SelectMany ( type => type . GetMethods ( ) )
52- . Where ( method => method . IsPublic && method . IsDefined ( typeof ( HttpGetAttribute ) ) && ! method . IsDefined ( typeof ( NonActionAttribute ) ) && Utility . GetHierarchicalAttributeOrNull < ResourceContainsSecretsAttribute > ( method ) == null ) . ToArray ( ) ;
54+ . Where ( method => HasNonAttributedGetAction ( method ) ) . ToArray ( ) ;
5355 var methodNames = methodInfos . Select ( p => $ "{ p . DeclaringType . Name } .{ p . Name } ") . OrderBy ( p => p ) . ToArray ( ) ;
5456
5557 // if this check is failing, it means you've added new host GET API. If the API doesn't return secrets (i.e. is safe for an ARM Reader),
5658 // add it to the list above. If the API returns secrets, apply the ResourceContainsSecretsAttribute to the action method.
5759 Assert . Equal ( safeReaderApis , methodNames ) ;
5860 }
61+
62+ private bool HasNonAttributedGetAction ( MethodInfo method )
63+ {
64+ if ( ! method . IsPublic || method . IsDefined ( typeof ( NonActionAttribute ) ) )
65+ {
66+ return false ;
67+ }
68+
69+ bool supportsGet = false ;
70+ foreach ( var attribute in method . GetCustomAttributes ( ) )
71+ {
72+ if ( attribute is IActionHttpMethodProvider httpMethodProvider &&
73+ httpMethodProvider . HttpMethods . Contains ( "GET" , StringComparer . OrdinalIgnoreCase ) )
74+ {
75+ supportsGet = true ;
76+ break ;
77+ }
78+ }
79+
80+ return supportsGet && Utility . GetHierarchicalAttributeOrNull < ResourceContainsSecretsAttribute > ( method ) == null ;
81+ }
5982 }
6083}
0 commit comments