【发布时间】:2023-03-30 05:19:01
【问题描述】:
有php-code,返回svg-image。
public function actionJsTest() {
header('Content-Type: image/svg+xml');
$svg = '';
$svg .= '<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">';
$svg .= '<script type="text/javascript">';
$svg .= '<![CDATA[';
$svg .= 'alert();';
$svg .= ']]>';
$svg .= '</script>';
$svg .= '<rect x="0" y="0" height="10" width="10" style="stroke-width:1; stroke:black; fill:red"></rect>';
$svg .= '<circle cx="250" cy="250" r="50" stroke="red" stroke-width="1" fill="red"></circle>';
$svg .= '</svg>';
echo $svg;
}
当我们直接在视图中调用 php 函数时,它工作正常并触发警报。
当我们使用标签从 html 页面显示该 svg 时:
<img src="http://givemesvg.php"/> - SVG 显示正确,但不会触发警报。
这是浏览器安全策略还是遗漏了什么?谢谢。
【问题讨论】:
标签: javascript php html security svg