Skip to content
Merged
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
feat(util): add QueryParameter()
  • Loading branch information
jbrockopp committed May 23, 2022
commit b6532553eb6c4310c4b55c7a53a112994803e17b
39 changes: 26 additions & 13 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@ func HandleError(c *gin.Context, status int, err error) {
c.AbortWithStatusJSON(status, types.Error{Message: &msg})
}

// GetParameter safely captures a parameter from the context by
// removing any new lines and HTML escaping the value.
func GetParameter(c *gin.Context, parameter string) string {
// capture the raw value for the parameter
raw := c.Param(parameter)

// replace all new lines in the value for the parameter
escaped := strings.Replace(strings.Replace(raw, "\n", "", -1), "\r", "", -1)

// HTML escape the new line escaped value for the parameter
return html.EscapeString(escaped)
}

// MaxInt is a helper function to clamp the integer which
// prevents it from being higher then the provided value.
//
Expand All @@ -56,3 +43,29 @@ func MinInt(a, b int) int {

return b
}

// QueryParameter safely captures a query parameter from the context
// by removing any new lines and HTML escaping the value.
func QueryParameter(c *gin.Context, parameter, value string) string {
// capture the raw value for the query parameter
raw := c.DefaultQuery(parameter, value)

// replace all new lines in the value for the parameter
escaped := strings.Replace(strings.Replace(raw, "\n", "", -1), "\r", "", -1)

// HTML escape the new line escaped value for the parameter
return html.EscapeString(escaped)
}

// PathParameter safely captures a path parameter from the context
// by removing any new lines and HTML escaping the value.
func PathParameter(c *gin.Context, parameter string) string {
// capture the raw value for the path parameter
raw := c.Param(parameter)

// replace all new lines in the value for the parameter
escaped := strings.Replace(strings.Replace(raw, "\n", "", -1), "\r", "", -1)

// HTML escape the new line escaped value for the parameter
return html.EscapeString(escaped)
}