File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
src/SecurityTokenService/Middlewares Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -14,13 +14,27 @@ public class DecryptRequestMiddleware(RequestDelegate next)
1414 private const string VersionHeader = "Z-Encrypt-Version" ;
1515 private const string KeyHeader = "Z-Encrypt-Key" ;
1616
17+ private static readonly bool ForceEncryptedBody =
18+ bool . Parse ( Environment . GetEnvironmentVariable ( "STS_FORCE_ENCRYPTED_BODY" ) ?? "false" ) ;
19+
1720 public async Task InvokeAsync ( HttpContext context , ILogger < DecryptRequestMiddleware > logger )
1821 {
1922 var encryptVersion = context . Request . Headers [ VersionHeader ] . ElementAtOrDefault ( 0 ) ;
2023 var encryptKey = context . Request . Headers [ KeyHeader ] . ElementAtOrDefault ( 0 ) ;
2124
2225 var encryptVersionIsNullOrEmpty = string . IsNullOrEmpty ( encryptVersion ) ;
2326 var encryptKeyIsNullOrEmpty = string . IsNullOrEmpty ( encryptKey ) ;
27+ var path = context . Request . Path . Value ? . ToLowerInvariant ( ) ;
28+ if (
29+ ForceEncryptedBody && path != null &&
30+ path . Contains ( "/account/" , StringComparison . InvariantCultureIgnoreCase ) &&
31+ ( encryptVersionIsNullOrEmpty || encryptKeyIsNullOrEmpty )
32+ )
33+ {
34+ // 检查到开启强制加密时,account 路由必须参数加密
35+ context . Response . StatusCode = StatusCodes . Status403Forbidden ;
36+ return ;
37+ }
2438
2539 // 若未传加密版本号和加密密钥, 则不解密
2640 if ( encryptVersionIsNullOrEmpty && encryptKeyIsNullOrEmpty )
You can’t perform that action at this time.
0 commit comments