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

fix: ext-auth crash bugfix #1705

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions plugins/wasm-go/extensions/ext-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (
)

func onHttpRequestHeaders(ctx wrapper.HttpContext, config config.ExtAuthConfig, log wrapper.Log) types.Action {
path, _ := wrapper.GetRequestPathWithoutQuery()
path := wrapper.GetRequestPathWithoutQuery()
// If the request's domain and path match the MatchRules, skip authentication
if config.MatchRules.IsAllowedByMode(ctx.Host(), path) {
ctx.DontReadRequestBody()
Expand All @@ -77,7 +77,7 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, config config.ExtAuthConfig,

func onHttpRequestBody(ctx wrapper.HttpContext, config config.ExtAuthConfig, body []byte, log wrapper.Log) types.Action {
if config.HttpService.AuthorizationRequest.WithRequestBody {
return checkExtAuth(ctx, config, body, log, types.ActionPause)
return checkExtAuth(ctx, config, body, log, types.DataStopIterationAndBuffer)
}
return types.ActionContinue
}
Expand All @@ -86,6 +86,8 @@ func checkExtAuth(ctx wrapper.HttpContext, cfg config.ExtAuthConfig, body []byte
httpServiceConfig := cfg.HttpService

extAuthReqHeaders := buildExtAuthRequestHeaders(ctx, cfg)

// Set the requestMethod and requestPath based on the endpoint_mode
requestMethod := httpServiceConfig.RequestMethod
requestPath := httpServiceConfig.Path
if httpServiceConfig.EndpointMode == config.EndpointModeEnvoy {
Expand All @@ -96,7 +98,6 @@ func checkExtAuth(ctx wrapper.HttpContext, cfg config.ExtAuthConfig, body []byte
// Call ext auth server
err := httpServiceConfig.Client.Call(requestMethod, requestPath, util.ReconvertHeaders(extAuthReqHeaders), body,
func(statusCode int, responseHeaders http.Header, responseBody []byte) {
defer proxywasm.ResumeHttpRequest()
if statusCode != http.StatusOK {
log.Errorf("failed to call ext auth server, status: %d", statusCode)
callExtAuthServerErrorHandler(cfg, statusCode, responseHeaders, responseBody)
Expand All @@ -110,6 +111,7 @@ func checkExtAuth(ctx wrapper.HttpContext, cfg config.ExtAuthConfig, body []byte
}
}
}
proxywasm.ResumeHttpRequest()

}, httpServiceConfig.Timeout)

Expand All @@ -122,6 +124,7 @@ func checkExtAuth(ctx wrapper.HttpContext, cfg config.ExtAuthConfig, body []byte
return pauseAction
}

// buildExtAuthRequestHeaders builds the request headers to be sent to the ext auth server.
func buildExtAuthRequestHeaders(ctx wrapper.HttpContext, cfg config.ExtAuthConfig) http.Header {
extAuthReqHeaders := http.Header{}

Expand Down Expand Up @@ -166,6 +169,7 @@ func callExtAuthServerErrorHandler(config config.ExtAuthConfig, statusCode int,
if config.FailureModeAllowHeaderAdd {
_ = proxywasm.ReplaceHttpRequestHeader(HeaderFailureModeAllow, "true")
}
proxywasm.ResumeHttpRequest()
return
}

Expand Down
10 changes: 7 additions & 3 deletions plugins/wasm-go/pkg/wrapper/request_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ func GetRequestPath() string {
return path
}

func GetRequestPathWithoutQuery() (string, error) {
func GetRequestPathWithoutQuery() string {
rawPath := GetRequestPath()
if rawPath == "" {
return ""
}
path, err := url.Parse(rawPath)
if err != nil {
return "", err
proxywasm.LogErrorf("failed to parse request path '%s': %v", rawPath, err)
return ""
}
return path.Path, nil
return path.Path
}

func GetRequestMethod() string {
Expand Down
Loading