【发布时间】:2021-04-12 11:55:39
【问题描述】:
在我们的项目中,我们目前正在使用 Fortify 扫描仪来扫描我们的代码,我们有一个有趣的问题。我们正在考虑类似
@PathVariable (required = true) String id
Spring 已经对它进行了清理,但在我们的例子中,它在以下上下文中使用时会引发问题
@RequestMapping(
method = RequestMethod.DELETE,
path = "/{id}",
consumes = "application/json"
)
public ResponseEntity cancelTask(
@PathVariable (required = true) String id,
@RequestBody (required = false) String reason
) {
String userId = authenticationContext.getUserId();
if (!authorizationService.hasPermission(userId, id, TaskAccessRight.EDIT)) { log.warn("User {} is not authorized to cancel task {}", userId, id);
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Not authorized to cancel task " + id);
}
...
}
Fortify 将此标记为跨站点脚本:反映问题。
我的问题是真的可以通过说 id 来利用
<script>alert('Hello Jack')</script>
作为路径输入...如果是这样,我们应该如何在正文中对其进行消毒?
我们不确定这是否经过消毒,所以我们不确定这是误报,有人可以确认 Spring 会自动处理这个问题吗?
我们有几十个由 fortify 提出的类似问题
【问题讨论】:
-
您是否尝试通过
@PathVariable实际发送带有 HTML+Javascript 的字符串?我得到 500 -The request was rejected because the URL contained a potentially malicious String \"//\"或 400 -The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing)。在我看来,Spring 阻止了不属于路径层次结构的正斜杠(例如(转义/编码)。
标签: spring spring-boot sanitization fortify