修復UNIGUI安全掃描出現“啟用了不安全的 HTTP 方法”
阿新 • • 發佈:2020-11-13
使用1.90.0.1535編譯的應用做安全掃描時發現有“啟用了不安全的HTTP方法”,這個漏洞的影響是:可能會在Web伺服器上上載、修改或刪除Web頁面、指令碼。
如果使用Tomcat修復很簡單,直接修改的web.xml就可以:
<security-constraint> <web-resource-collection> <web-resource-name>fortune</web-resource-name> <url-pattern>/*</url-pattern> <http-method>PUT</http-method> <http-method>DELETE</http-method> <http-method>HEAD</http-method> <http-method>OPTIONS</http-method> <http-method>TRACE</http-method> </web-resource-collection> <auth-constraint></auth-constraint> </security-constraint>
需然用AWS能掃出這漏洞,但驗證後發現UniGui編譯的伺服器並沒實現HEAD,DELETE,PUT,TRACE,OPTION,這些命令的功能需要自行編寫才可以。
知道原因後解決起來很簡單:當執行HEAD,DELETE,PUT,TRACE,OPTION等命令時直接返回403就可以。在ServerModule單元HTTPCommand新增下面的程式碼就可以。
procedure UniGUIServerModuleHTTPCommand(ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo; var Handled: Boolean);
procedure TUniServerModule.UniGUIServerModuleHTTPCommand( ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var Handled: Boolean); begin if (ARequestInfo.CommandType =hcHEAD) or (ARequestInfo.CommandType =hcPUT) or (ARequestInfo.CommandType =hcTRACE) or (ARequestInfo.CommandType =hcOPTION) or (ARequestInfo.CommandType =hcDELETE) then begin Handled := false; AResponseInfo.ResponseText:='Fail'; AResponseInfo.ResponseNo:=403; AResponseInfo.CloseConnection:=true; AResponseInfo.Server:='D2021'; AResponseInfo.CharSet := 'UTF-8'; AResponseInfo.ContentType := 'Text'; AResponseInfo.ContentText := '本軟體不支援HEAD,DELETE,PUT,TRACE,OPTION等命令!'; end; end;