Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
masx200 opened this issue Aug 17, 2021 · 3 comments

Comments

@masx200
Copy link

masx200 commented Aug 17, 2021

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

beego/beego#4726

@flycash
Copy link
Collaborator

flycash commented Aug 18, 2021

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

@kotori2
Copy link

kotori2 commented Mar 28, 2023

确实是……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
Copy link

kotori2 commented Mar 28, 2023

确实是……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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants