SecureJSON

未匹配的标注

使用 SecureJSON 防止 json 劫持。如果给定的结构是数组值,则默认预置 "while(1)," 到响应体。

func main() {
    r := gin.Default()

    // 你也可以使用自己的 SecureJSON 前缀
    // r.SecureJsonPrefix(")]}',\n")

    r.GET("/someJSON", func(c *gin.Context) {
        names := []string{"lena", "austin", "foo"}

        // 将输出:while(1);["lena","austin","foo"]
        c.SecureJSON(http.StatusOK, names)
    })

    // 监听并在 0.0.0.0:8080 上启动服务
    r.Run(":8080")
}

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
讨论数量: 1
发起讨论 只看当前版本


Mr-houzi
SecureJSON是怎么防止JSON劫持的?
0 个点赞 | 2 个回复 | 问答 | 课程版本 2019