beedoc icon indicating copy to clipboard operation
beedoc copied to clipboard

为什么文档中没有写到跨域的支持呢?还要我到issue里面搜索出来

Open masx200 opened this issue 3 years ago • 3 comments

为什么文档中没有写到跨域的支持呢?还要我到issue里面搜索出来

https://github.com/beego/beego/issues/4726

masx200 avatar Aug 17 '21 02:08 masx200

你搜出来之后可以给我们发一个PR,发到这个仓库就可以的,社区需要大家一起改进

flycash avatar Aug 18 '21 14:08 flycash

确实是……CORS这么重要的安全问题应该被重视。 https://github.com/beego/beego/blob/develop/server/web/filter/cors/cors_test.go

	recorder := httptest.NewRecorder()
	handler := web.NewControllerRegister()
	handler.InsertFilter("*", web.BeforeRouter, Allow(&Options{
		AllowOrigins: []string{"https://aaa.com", "https://*.foo.com"},
	}))
	handler.Any("/foo", func(ctx *context.Context) {
		ctx.Output.SetStatus(500)
	})
	origin := "https://bar.foo.com"
	r, _ := http.NewRequest("PUT", "/foo", nil)
	r.Header.Add("Origin", origin)
	handler.ServeHTTP(recorder, r)

但是似乎流量全都经过NewRecorder了,和正常web.Run的行为不一致。所以我也很好奇这个问题要怎么解决。

kotori2 avatar Mar 28 '23 07:03 kotori2

确实是……CORS这么重要的安全问题应该被重视。 https://github.com/beego/beego/blob/develop/server/web/filter/cors/cors_test.go

	recorder := httptest.NewRecorder()
	handler := web.NewControllerRegister()
	handler.InsertFilter("*", web.BeforeRouter, Allow(&Options{
		AllowOrigins: []string{"https://aaa.com", "https://*.foo.com"},
	}))
	handler.Any("/foo", func(ctx *context.Context) {
		ctx.Output.SetStatus(500)
	})
	origin := "https://bar.foo.com"
	r, _ := http.NewRequest("PUT", "/foo", nil)
	r.Header.Add("Origin", origin)
	handler.ServeHTTP(recorder, r)

但是似乎流量全都经过NewRecorder了,和正常web.Run的行为不一致。所以我也很好奇这个问题要怎么解决。

Use web.InsertFilter with the same arguments.

kotori2 avatar Mar 28 '23 08:03 kotori2