File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 22// The .NET Foundation licenses this file to you under the MIT license.
33
44using Microsoft . AspNetCore . Builder ;
5- using Microsoft . AspNetCore . HttpOverrides ;
65using Microsoft . Extensions . Configuration ;
76using Microsoft . Extensions . Options ;
7+ using System . Net ;
88
99namespace Microsoft . AspNetCore ;
1010
@@ -50,16 +50,22 @@ public void Configure(ForwardedHeadersOptions options)
5050 options . KnownIPNetworks . Clear ( ) ;
5151 options . KnownProxies . Clear ( ) ;
5252
53- var knownNetworks = _configuration [ "ForwardedHeaders_KnownNetworks " ] ? . Split ( ',' , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries ) ?? [ ] ;
53+ var knownNetworks = _configuration [ "ForwardedHeaders_KnownIPNetworks " ] ? . Split ( ',' , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries ) ?? [ ] ;
5454 foreach ( var network in knownNetworks )
5555 {
56- options . KnownNetworks . Add ( IPNetwork . Parse ( network ) ) ;
56+ if ( IPNetwork . TryParse ( network , var ipNetwork ) )
57+ {
58+ options . KnownIPNetworks . Add ( ipNetwork ) ;
59+ }
5760 }
5861
5962 var knownProxies = _configuration [ "ForwardedHeaders_KnownProxies" ] ? . Split ( ',' , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries ) ?? [ ] ;
6063 foreach ( var proxy in knownProxies )
6164 {
62- options . KnownProxies . Add ( System . Net . IPAddress . Parse ( proxy ) ) ;
65+ if ( IPAddress . TryParse ( proxy , out var ipAddress ) )
66+ {
67+ options . KnownProxies . Add ( ipAddress ) ;
68+ }
6369 }
6470 }
6571}
You can’t perform that action at this time.
0 commit comments