Forgot password?
 Create new account
View 268|Reply 10

DiscuzX单行script被去掉

[Copy link]

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

hbghlyj Posted at 2022-2-18 20:36:19 |Read mode
Last edited by hbghlyj at 2024-10-22 17:04:00在Chrome中禁用了Javascript后仍不看见单行script标签,说明是后台的问题...是不是DiscuzX对内容的安全过滤

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-7-19 17:27:15
今日找到原因:
function_discuzcode.php里第99-103行,
        if(!$htmlon) {
                $
message = dhtmlspecialchars($message);
        } else {
               
$message = preg_replace("/<script[^\>]*?>(.*?)<\/script>/i", '', $message);
        }

else里面, 是html开启的情况下, 单行的<script>被去掉了.
我推测, Discuz 作者是为了安全, 想把<script>去掉, 但是上面的代码并不能把多行的<script>去掉.
我去Discuz那里反映了一下问题: gitee.com/Discuz/DiscuzX/issues/I5HTNO

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2022-8-5 13:51:20
hbghlyj 发表于 2022-7-19 17:27
今日找到原因:
在function_discuzcode.php里第99-103行,
        ...
我推测, Discuz 作者是为了安全, 想把<script>去掉, 但是上面的代码并不能把多行的<script>去掉.
那如果是要把多行的<script>也去掉,该改成什么呢?

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2022-8-5 22:26:02
hbghlyj 发表于 2022-8-5 21:56
如果是要把多行的也去掉,只要在/.../后面加上m,见Pattern Modifiers
话说,为啥要把多行的也去掉呢{:shuai ...
既然 Discuz 作者是为了安全,那我就帮他安全到底啊😏

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-8-5 22:28:17
kuing 发表于 2022-8-5 15:26
既然 Discuz 作者是为了安全,那我就帮他安全到底啊😏
建议允许 HTML 代码使用 JS 脚本
HTML 代码本质上就是 HTML CSS JAVASCRIPT , 如果屏蔽 JAVASCRIPT 那么 HTML 代码帖将失去许多实用价值。

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2022-9-14 02:05:50
如果是要把多行的也去掉,只要在/.../后面加上m,见Pattern Modifiers

我觉得不是要加 m 而是加 s

现在不匹配多行是因为:默认情况下的圆点 . 是匹配除换行符 \n 之外的任何字符。

加上 s 修饰符之后 . 中包含换行符 \n。

多行匹配修饰符 m 并不是你理解的那样。

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-9-14 06:00:25
kuing 发表于 2022-9-13 19:05
我觉得不是要加 m 而是加 s

现在不匹配多行是因为:默认情况下的圆点 . 是匹配除换行符 \n 之外的任何字 ...
对对. 我看了 RegExp.prototype.dotAll控制 Whether . matches newlines or not.
RegExp.prototype.multiline控制 ^ 和 $ 是否匹配由 \n 换行导致的行首和行尾
确实是加s.

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-9-14 06:06:15
可以看一下,控制台有'Test'
  1. <script>
  2. console.log('Test')
  3. </script >
Copy the Code

多一个空格,可以被浏览器识别

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-9-14 06:07:47
呼籲@kuing將function_discuzcode.php第99-103行去除
這樣單行<script>便不會被去除了
保持和舊論壇的一致性


701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2022-9-14 12:00:14
hbghlyj 发表于 2022-9-14 06:07
@kuing 建议将function_discuzcode.php第99-103行去除,这样单行就不会被去除了
保持和旧论坛的一致性{:smil ...
再说我就加 s

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-9-14 12:01:42
拜託千萬不要加s呀
很多舊帖子就不能正常顯示了


手机版Mobile version|Leisure Math Forum

2025-4-20 22:06 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list