Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
57e5162
Merge branch 'master' of github.com:go-vela/server
jbrockopp Feb 23, 2022
b6b840c
Merge branch 'master' of github.com:go-vela/server
jbrockopp Mar 10, 2022
858c818
Merge branch 'master' of github.com:go-vela/server
jbrockopp Mar 16, 2022
ceddb11
Merge branch 'master' of github.com:go-vela/server
jbrockopp Mar 28, 2022
331b2a2
Merge branch 'master' of github.com:go-vela/server
jbrockopp Apr 11, 2022
c4ec5fb
Merge branches 'master' and 'master' of github.com:go-vela/server
jbrockopp Apr 18, 2022
30c1151
Merge branch 'master' of github.com:go-vela/server
jbrockopp Apr 20, 2022
0ddc31c
Merge branch 'master' of github.com:go-vela/server
jbrockopp Apr 27, 2022
890f9fa
Merge branch 'master' of github.com:go-vela/server
jbrockopp May 9, 2022
cf4ca0e
Merge branch 'master' of github.com:go-vela/server
jbrockopp May 20, 2022
089d373
fix(middleware): HTML escape path parameters
jbrockopp May 22, 2022
1e17cca
chore: fix typo
jbrockopp May 22, 2022
17d90fc
fix(api): HTML escape path parameters
jbrockopp May 22, 2022
a79e61f
fix: org -> o rename
jbrockopp May 22, 2022
bac43e1
test: replacing newlines for pipeline parameter
jbrockopp May 23, 2022
ede359f
feat(util): add GetParameter()
jbrockopp May 23, 2022
9180509
fix(middleware): safely escape path parameters
jbrockopp May 23, 2022
71474d5
fix(api): safely escape path parameters
jbrockopp May 23, 2022
d3ca797
fix(middleware): safely escape query parameters
jbrockopp May 23, 2022
a3a5f64
fix(api): safely escape query parameters
jbrockopp May 23, 2022
b653255
feat(util): add QueryParameter()
jbrockopp May 23, 2022
b13aed7
fix(api): safely escape form parameters
jbrockopp May 23, 2022
c8ecaf5
feat(util): add FormParameter()
jbrockopp May 23, 2022
f2e198e
fix(middleware): escape logged path
jbrockopp May 23, 2022
c009294
chore: fix imports
jbrockopp May 23, 2022
a70b3b1
fix(middleware): escape logged fields
jbrockopp May 23, 2022
d72e057
feat(util): add EscapeValue()
jbrockopp May 23, 2022
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
Prev Previous commit
Next Next commit
fix(middleware): HTML escape path parameters
  • Loading branch information
jbrockopp committed May 22, 2022
commit 089d3733413ff408c28548ef4c33b719a686b769
13 changes: 6 additions & 7 deletions router/middleware/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ package build

import (
"fmt"
"html"
"net/http"
"strconv"

"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/user"

"github.com/gin-gonic/gin"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/util"
"github.com/go-vela/types/library"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

Expand All @@ -34,13 +33,13 @@ func Establish() gin.HandlerFunc {
u := user.Retrieve(c)

if r == nil {
retErr := fmt.Errorf("repo %s/%s not found", c.Param("org"), c.Param("repo"))
retErr := fmt.Errorf("repo %s/%s not found", html.EscapeString(c.Param("org")), html.EscapeString(c.Param("repo")))
util.HandleError(c, http.StatusNotFound, retErr)

return
}

bParam := c.Param("build")
bParam := html.EscapeString(c.Param("build"))
if len(bParam) == 0 {
retErr := fmt.Errorf("no build parameter provided")
util.HandleError(c, http.StatusBadRequest, retErr)
Expand Down
11 changes: 4 additions & 7 deletions router/middleware/executors/executors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ package executors
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"

"github.com/go-vela/types/library"

"github.com/gin-gonic/gin"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/util"

"fmt"
"net/http"

"github.com/gin-gonic/gin"
"github.com/go-vela/types/library"
)

// Retrieve gets the executors in the given context.
Expand Down
7 changes: 4 additions & 3 deletions router/middleware/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
package org

import (
"github.com/go-vela/server/util"

"fmt"
"html"
"net/http"

"github.com/gin-gonic/gin"
"github.com/go-vela/server/util"
)

// Retrieve gets the org in the given context.
Expand All @@ -21,7 +21,7 @@ func Retrieve(c *gin.Context) string {
// Establish used to check if org param is used only.
func Establish() gin.HandlerFunc {
return func(c *gin.Context) {
oParam := c.Param("org")
oParam := html.EscapeString(c.Param("org"))
if len(oParam) == 0 {
retErr := fmt.Errorf("no org parameter provided")
util.HandleError(c, http.StatusBadRequest, retErr)
Expand All @@ -30,6 +30,7 @@ func Establish() gin.HandlerFunc {
}

ToContext(c, oParam)

c.Next()
}
}
13 changes: 6 additions & 7 deletions router/middleware/perm/perm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ package perm

import (
"fmt"
"html"
"net/http"
"strings"

"github.com/gin-gonic/gin"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -52,10 +51,10 @@ func MustPlatformAdmin() gin.HandlerFunc {
func MustSecretAdmin() gin.HandlerFunc {
return func(c *gin.Context) {
u := user.Retrieve(c)
e := c.Param("engine")
t := c.Param("type")
o := c.Param("org")
n := c.Param("name")
e := html.EscapeString(c.Param("engine"))
t := html.EscapeString(c.Param("type"))
o := html.EscapeString(c.Param("org"))
n := html.EscapeString(c.Param("name"))
m := c.Request.Method

// create log fields from API metadata
Expand Down
9 changes: 5 additions & 4 deletions router/middleware/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package pipeline

import (
"fmt"
"html"
"net/http"

"github.com/gin-gonic/gin"
Expand All @@ -31,14 +32,14 @@ func Establish() gin.HandlerFunc {
u := user.Retrieve(c)

if r == nil {
retErr := fmt.Errorf("repo %s/%s not found", c.Param("org"), c.Param("repo"))
retErr := fmt.Errorf("repo %s/%s not found", html.EscapeString(c.Param("org")), html.EscapeString(c.Param("repo")))

util.HandleError(c, http.StatusNotFound, retErr)

return
}

p := c.Param("pipeline")
p := html.EscapeString(c.Param("pipeline"))
if len(p) == 0 {
retErr := fmt.Errorf("no pipeline parameter provided")

Expand All @@ -52,10 +53,10 @@ func Establish() gin.HandlerFunc {
// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#Entry.WithFields
logrus.WithFields(logrus.Fields{
"org": o,
"pipeline": p,
"pipeline": html.EscapeString(p),
"repo": r.GetName(),
"user": u.GetName(),
}).Debugf("reading pipeline %s/%s", r.GetFullName(), p)
}).Debugf("reading pipeline %s/%s", r.GetFullName(), html.EscapeString(p))

pipeline, err := database.FromContext(c).GetPipelineForRepo(p, r)
if err != nil {
Expand Down
17 changes: 8 additions & 9 deletions router/middleware/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
package repo

import (
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/types/library"
"github.com/sirupsen/logrus"

"github.com/go-vela/server/database"
"github.com/go-vela/server/util"

"fmt"
"html"
"net/http"

"github.com/gin-gonic/gin"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/util"
"github.com/go-vela/types/library"
"github.com/sirupsen/logrus"
)

// Retrieve gets the repo in the given context.
Expand All @@ -30,7 +29,7 @@ func Establish() gin.HandlerFunc {
o := org.Retrieve(c)
u := user.Retrieve(c)

rParam := c.Param("repo")
rParam := html.EscapeString(c.Param("repo"))
if len(rParam) == 0 {
retErr := fmt.Errorf("no repo parameter provided")
util.HandleError(c, http.StatusBadRequest, retErr)
Expand Down
15 changes: 7 additions & 8 deletions router/middleware/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ package service

import (
"fmt"
"html"
"net/http"
"strconv"

"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/user"

"github.com/gin-gonic/gin"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/util"
"github.com/go-vela/types/library"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

Expand All @@ -37,20 +36,20 @@ func Establish() gin.HandlerFunc {
u := user.Retrieve(c)

if r == nil {
retErr := fmt.Errorf("repo %s/%s not found", o, c.Param("repo"))
retErr := fmt.Errorf("repo %s/%s not found", o, html.EscapeString(c.Param("repo")))
util.HandleError(c, http.StatusNotFound, retErr)

return
}

if b == nil {
retErr := fmt.Errorf("build %s not found for repo %s", c.Param("build"), r.GetFullName())
retErr := fmt.Errorf("build %s not found for repo %s", html.EscapeString(c.Param("build")), r.GetFullName())
util.HandleError(c, http.StatusNotFound, retErr)

return
}

sParam := c.Param("service")
sParam := html.EscapeString(c.Param("service"))
if len(sParam) == 0 {
retErr := fmt.Errorf("no service parameter provided")
util.HandleError(c, http.StatusBadRequest, retErr)
Expand Down
15 changes: 7 additions & 8 deletions router/middleware/step/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ package step

import (
"fmt"
"html"
"net/http"
"strconv"

"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/user"

"github.com/gin-gonic/gin"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/util"
"github.com/go-vela/types/library"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

Expand All @@ -37,20 +36,20 @@ func Establish() gin.HandlerFunc {
u := user.Retrieve(c)

if r == nil {
retErr := fmt.Errorf("repo %s/%s not found", o, c.Param("repo"))
retErr := fmt.Errorf("repo %s/%s not found", o, html.EscapeString(c.Param("repo")))
util.HandleError(c, http.StatusNotFound, retErr)

return
}

if b == nil {
retErr := fmt.Errorf("build %s not found for repo %s", c.Param("build"), r.GetFullName())
retErr := fmt.Errorf("build %s not found for repo %s", html.EscapeString(c.Param("build")), r.GetFullName())
util.HandleError(c, http.StatusNotFound, retErr)

return
}

sParam := c.Param("step")
sParam := html.EscapeString(c.Param("step"))
if len(sParam) == 0 {
retErr := fmt.Errorf("no step parameter provided")
util.HandleError(c, http.StatusBadRequest, retErr)
Expand Down
11 changes: 5 additions & 6 deletions router/middleware/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
package worker

import (
"github.com/go-vela/server/database"
"github.com/go-vela/types/library"

"github.com/go-vela/server/util"

"fmt"
"html"
"net/http"

"github.com/gin-gonic/gin"
"github.com/go-vela/server/database"
"github.com/go-vela/server/util"
"github.com/go-vela/types/library"
"github.com/sirupsen/logrus"
)

Expand All @@ -25,7 +24,7 @@ func Retrieve(c *gin.Context) *library.Worker {
// Establish sets the worker in the given context.
func Establish() gin.HandlerFunc {
return func(c *gin.Context) {
wParam := c.Param("worker")
wParam := html.EscapeString(c.Param("worker"))
if len(wParam) == 0 {
retErr := fmt.Errorf("no worker parameter provided")
util.HandleError(c, http.StatusBadRequest, retErr)
Expand Down