Java:从HTML中删除Javascript的最佳方法

编程入门 行业动态 更新时间:2024-10-23 19:33:30
本文介绍了Java:从HTML中删除Javascript的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

从HTML中删除将要显示的Javascript的最佳库/方法是什么?

What's the best library/approach for removing Javascript from HTML that will be displayed?

例如,取:

<html><body><span onmousemove='doBadXss()'>test</span></body></html>

并离开:

<html><body><span>test</span></body></html>

我看到 DeXSS 项目。但这是最好的方法吗?

I see the DeXSS project. But is that the best way to go?

推荐答案

JSoup有一种基于白名单清理HTML的简单方法。 查看 jsoup/cookbook/cleaning-html/whitelist-消毒剂

JSoup has a simple method for sanitizing HTML based on a whitelist. Check jsoup/cookbook/cleaning-html/whitelist-sanitizer

它使用白名单,这比DeXSS使用的黑名单方法更安全。来自DeXSS页面:

It uses a whitelist, which is safer then the blacklist approach DeXSS uses. From the DeXSS page:

DeXSS尚未检测到许多已知的XSS攻击。

There are still a number of known XSS attacks that DeXSS does not yet detect.

黑名单只允许已知的不安全结构,而白名单只允许已知的安全结构。如此未知,可能不安全的结构只会受到白名单的保护。

A blacklist only disallows known unsafe constructions, while a whitelist only allows known safe constructions. So unknown, possibly unsafe constructions will only be protected against with a whitelist.

更多推荐

Java:从HTML中删除Javascript的最佳方法

本文发布于:2023-11-01 18:28:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550080.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   Java   HTML   Javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!