1.5 Web跨域

1.5.1【必须】跨域资源共享CORS限制请求来源

  • CORS请求保护不当可导致敏感信息泄漏,因此应当严格设置Access-Control-Allow-Origin使用同源策略进行保护。
  1. // good
  2. c := cors.New(cors.Options{
  3. AllowedOrigins: []string{"http://qq.com", "https://qq.com"},
  4. AllowCredentials: true,
  5. Debug: false,
  6. })
  7. //引入中间件
  8. handler = c.Handler(handler)