2.5 JSX Prevents Injection Attacks JSX防止注入攻击

It is safe to embed user input in JSX:

像这样在JSX中嵌入用户输入是安全的:

const title = response.potentiallyMaliciousInput;
// This is safe:
const element =<h1>{title}</h1>;

By default, React DOM escapes any values embedded in JSX before rendering them.

默认情况,React DOM会在渲染前对嵌入JSX内的值进行转意。

Thus it ensures that you can never inject anything that's not explicitly written in your application.

这样做将确保你的应用不会被没有明确写的的东西注入。

Everything is converted to a string before being rendered. This helps prevent XSS (cross-site-scripting) attacks.

每个东西再被渲染前都会被转换为字符串。这样做会有效的防止XSS(跨站脚本)攻击。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容