fix: the backend link show and confirm POSTs ignore a code in the query string
readFields falls back to r.Form, which includes the query string, so POST /backend-link/show?code=... and /confirm?code=... worked and put the code into access logs. Both routes now read the code from the body only (JSON or a form body).
This commit is contained in:
@@ -41,10 +41,11 @@ func BackendLinkShow(app *backpack.App) http.HandlerFunc {
|
||||
|
||||
// BackendLinkShowPost serves POST /_user/api/v1/backend-link/show: body
|
||||
// {"code": ...}, the same answers as BackendLinkShow. The code travels in
|
||||
// the body, so it stays out of the URLs servers and proxies log.
|
||||
// the body, so it stays out of the URLs servers and proxies log; a code in
|
||||
// the query string is ignored.
|
||||
func BackendLinkShowPost(app *backpack.App) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
fields, err := readFields(r)
|
||||
fields, err := readBodyFields(r)
|
||||
if err != nil {
|
||||
writeNoStoreJSON(w, http.StatusNotFound, map[string]any{"error": "not_found"})
|
||||
return
|
||||
@@ -85,6 +86,7 @@ func writeNoStoreJSON(w http.ResponseWriter, status int, v any) {
|
||||
// token without auth_time (minted before auth_time existed, or refreshed from
|
||||
// one), answers 409 with the stale-session error, an account already linked
|
||||
// on either side 409 already_linked, an unknown, used or expired code 404.
|
||||
// The code is read from the body only; one in the query string is ignored.
|
||||
func BackendLinkConfirm(app *backpack.App) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
principal, ok := bouncer.User(r.Context())
|
||||
@@ -108,7 +110,7 @@ func BackendLinkConfirm(app *backpack.App) http.HandlerFunc {
|
||||
writeJSON(w, http.StatusConflict, map[string]any{"error": "stale_session"})
|
||||
return
|
||||
}
|
||||
fields, err := readFields(r)
|
||||
fields, err := readBodyFields(r)
|
||||
if err != nil {
|
||||
linkNotFound(w)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user