layui / layui/layui

[Layer] inline javascript 触发CSP报错

Open
#3,068 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
30.6k
Forks
7.4k
Avg merge
7m
Merged PRs (30d)
1

Description

议题条件
  • 我确认已查看官方使用文档:https://layui.dev ,但没有找到相关解决方案。
  • 我确认已在 Issues 中搜索过类似的问题,但没有找到相关解决方案。
  • 我已仔细阅读: 🍀 Layui Issue 贡献指南
议题类型

功能请求

使用版本

2.13.7

问题描述

layer里面仍有部分代码会触发CSP 报错,注意到以前的关闭按钮抛弃了,变成了span,规避了javascript URL. layer的iframe里面仍然有onload 这种inline javascript

    times +
    '" onload="this.className=\'\';" class="lay-layer-load" frameborder="0" src="' +
    config.content[0] +
    '"></iframe>';

具体参见: https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP

业务代码
times +
        '" onload="this.className=\'\';" class="lay-layer-load" frameborder="0" src="' +
        config.content[0] +
        '"></iframe>';
截图补充

No response

浏览器

Chrome

演示地址

No response

友好承诺
  • 我承诺将本着相互尊重、理解和友善的态度进行交流,共同维护 Layui 良好的社区氛围。

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search the Layer implementation for the iframe template containing the shown onload attribute, then read how the iframe is created and loaded. Update the Layer behavior so this path works without inline JavaScript under CSP, and verify that the iframe still loads correctly without a CSP violation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.