搜尋
首頁Java避免在 spring-boot 中向客戶端暴露後端詳細信息

近日,php小編西瓜為您帶來了一篇關於Java方面的問答文章,重點討論瞭如何在spring-boot中避免向客戶端暴露後端詳細信息的問題。在開發過程中,如何處理異常訊息、錯誤提示等敏感訊息,避免洩露敏感數據,是開發者需要重點關注的問題之一。本文將為您解答這些疑惑,幫助您更好地保護應用程式的安全性。

問題內容

當遇到錯誤/不存在的 spring-boot 端點時。代碼層級的類別詳細資訊被公開。這可能會被標記為安全問題。

範例

請求

localhost:8500/api/1.0/service/../msc -> this is a bad formatted endpoint, which does not exist.

回應

{
    "timestamp": "2024-01-31t08:33:44.321+0000",
    "status": 400,
    "error": "bad request",
    "message": "failed to find lookuppath '/api/1.0/msc' within requesturi '/api/1.0/service/../msc'. this could be because the path has invalid encoded characters or isn't normalized.; nested exception is org.springframework.web.servlet.resource.resourceurlencodingfilter$lookuppathindexexception: failed to find lookuppath '/api/1.0/msc' within requesturi '/api/1.0/service/../msc'. this could be because the path has invalid encoded characters or isn't normalized.",
    "path": "/api/1.0/service/../msc"
}

只需查看錯誤訊息,我們就可以了解到有一個 spring-boot 應用程式在後台運行,由於訊息中公開了程式碼層級的詳細信息,因此它可能是一個漏洞。

我們如何向客戶端發送通用訊息而不是整個異常詳細資訊?

我也嘗試過使用@controlleradvice,但其中沒有捕獲異常。看起來這個問題甚至在到達控制器本身之前就已經出現了。

@ExceptionHandler(Exception.class)
public ResponseEntity handleException(Exception ex) {
log.error("Exception in flow", ex);
ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Internal Server Error");
}

解決方法

您可以使用多種方法的組合來處理該異常並且不洩漏它,請參閱https://www.php.cn/link/41fa3925a7ec42ce029c43d6676e4b2c 以檢查不同類型的處理程序。

以上是避免在 spring-boot 中向客戶端暴露後端詳細信息的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:stackoverflow。如有侵權,請聯絡admin@php.cn刪除

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器