Skip to content

Commit

Permalink
fix: use correct security annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Sep 28, 2020
1 parent a8a781c commit c9bebe0
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 51 deletions.
60 changes: 36 additions & 24 deletions internal/httpclient/client/public/public_client.go

Large diffs are not rendered by default.

64 changes: 60 additions & 4 deletions internal/httpclient/client/public/whoami_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions selfservice/errorx/handler.go
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/julienschmidt/httprouter"
"github.com/justinas/nosurf"
"github.com/pkg/errors"

"github.com/ory/herodot"

Expand Down Expand Up @@ -68,15 +67,12 @@ type getSelfServiceErrorParameters struct {
Error string `json:"error"`
}

// swagger:route GET /self-service/errors common public admin getSelfServiceError
// swagger:route GET /self-service/errors public admin getSelfServiceError
//
// Get User-Facing Self-Service Errors
//
// This endpoint returns the error associated with a user-facing self service errors.
//
// When accessing this endpoint through ORY Kratos' Public API, ensure that cookies are set as they are required for CSRF to work. To prevent
// token scanning attacks, the public endpoint does not return 404 status codes.
//
// This endpoint supports stub values to help you implement the error UI:
//
// - `?error=stub:500` - returns a stub 500 (Internal Server Error) error.
Expand All @@ -94,20 +90,20 @@ type getSelfServiceErrorParameters struct {
// 404: genericError
// 500: genericError
func (h *Handler) publicFetchError(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if err := h.fetchError(w, r, true); err != nil {
if err := h.fetchError(w, r); err != nil {
h.r.Writer().WriteError(w, r, x.ErrInvalidCSRFToken.WithTrace(err).WithDebugf("%s", err))
return
}
}

func (h *Handler) adminFetchError(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if err := h.fetchError(w, r, false); err != nil {
if err := h.fetchError(w, r); err != nil {
h.r.Writer().WriteError(w, r, err)
return
}
}

func (h *Handler) fetchError(w http.ResponseWriter, r *http.Request, mustVerify bool) error {
func (h *Handler) fetchError(w http.ResponseWriter, r *http.Request) error {
id := r.URL.Query().Get("error")
switch id {
case "stub:500":
Expand All @@ -120,10 +116,6 @@ func (h *Handler) fetchError(w http.ResponseWriter, r *http.Request, mustVerify
return err
}

if mustVerify && !nosurf.VerifyToken(h.csrf(r), es.CSRFToken) {
return errors.WithStack(x.ErrInvalidCSRFToken)
}

h.r.Writer().Write(w, r, es)
return nil
}
4 changes: 2 additions & 2 deletions selfservice/flow/login/handler.go
Expand Up @@ -114,7 +114,7 @@ type initializeSelfServiceBrowserLoginFlow struct {
// Schemes: http, https
//
// Security:
// - sessionToken
// sessionToken:
//
// Responses:
// 200: loginFlow
Expand Down Expand Up @@ -161,7 +161,7 @@ func (h *Handler) initAPIFlow(w http.ResponseWriter, r *http.Request, _ httprout
// Schemes: http, https
//
// Security:
// - sessionToken
// sessionToken:
//
// Responses:
// 302: emptyResponse
Expand Down
4 changes: 2 additions & 2 deletions selfservice/flow/recovery/handler.go
Expand Up @@ -84,7 +84,7 @@ func (h *Handler) RegisterAdminRoutes(admin *x.RouterAdmin) {
// Schemes: http, https
//
// Security:
// - sessionToken
// sessionToken:
//
// Responses:
// 200: recoveryFlow
Expand Down Expand Up @@ -120,7 +120,7 @@ func (h *Handler) initAPIFlow(w http.ResponseWriter, r *http.Request, _ httprout
// Schemes: http, https
//
// Security:
// - sessionToken
// sessionToken:
//
// Responses:
// 302: emptyResponse
Expand Down
4 changes: 2 additions & 2 deletions selfservice/flow/registration/handler.go
Expand Up @@ -104,7 +104,7 @@ func (h *Handler) NewRegistrationFlow(w http.ResponseWriter, r *http.Request, ft
// Schemes: http, https
//
// Security:
// - sessionToken
// sessionToken:
//
// Responses:
// 200: registrationFlow
Expand Down Expand Up @@ -140,7 +140,7 @@ func (h *Handler) initApiFlow(w http.ResponseWriter, r *http.Request, ps httprou
// Schemes: http, https
//
// Security:
// - sessionToken
// sessionToken:
//
// Responses:
// 302: emptyResponse
Expand Down
6 changes: 3 additions & 3 deletions selfservice/flow/settings/handler.go
Expand Up @@ -127,7 +127,7 @@ func (h *Handler) NewFlow(w http.ResponseWriter, r *http.Request, i *identity.Id
// Schemes: http, https
//
// Security:
// - sessionToken
// sessionToken:
//
// Responses:
// 200: settingsFlow
Expand Down Expand Up @@ -168,7 +168,7 @@ func (h *Handler) initApiFlow(w http.ResponseWriter, r *http.Request, _ httprout
// Schemes: http, https
//
// Security:
// - sessionToken
// sessionToken:
//
// Responses:
// 302: emptyResponse
Expand Down Expand Up @@ -220,7 +220,7 @@ type getSelfServiceSettingsFlowParameters struct {
// Schemes: http, https
//
// Security:
// - sessionToken
// sessionToken:
//
// Responses:
// 200: settingsFlow
Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/password/settings.go
Expand Up @@ -105,7 +105,7 @@ func (p *CompleteSelfServiceSettingsFlowWithPasswordMethod) SetFlowID(rid uuid.U
// - application/json
//
// Security:
// - sessionToken
// sessionToken:
//
// Schemes: http, https
//
Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/profile/strategy.go
Expand Up @@ -147,7 +147,7 @@ func (s *Strategy) PopulateSettingsMethod(r *http.Request, id *identity.Identity
// - application/json
//
// Security:
// - sessionToken
// sessionToken:
//
// Schemes: http, https
//
Expand Down

0 comments on commit c9bebe0

Please sign in to comment.