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

dev: hardening some of the dev tools and a few places in app code #3115

Merged
merged 5 commits into from
Jun 22, 2023
Merged
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
2 changes: 1 addition & 1 deletion devtools/configparams/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func ApplyConfigValues(cfg config.Config, vals []ConfigValueInput) (config.Confi
if v == "" {
return 0, nil
}
val, err := strconv.ParseInt(v, 10, 64)
val, err := strconv.ParseInt(v, 10, 32)
if err != nil {
return 0, validation.NewFieldError("\""+id+"\".Value", "integer value invalid: " + err.Error())
}
Expand Down
81 changes: 0 additions & 81 deletions devtools/mockslack/oauthauthorize.go

This file was deleted.

48 changes: 0 additions & 48 deletions devtools/mockslack/oauthauthorize.html

This file was deleted.

1 change: 0 additions & 1 deletion devtools/mockslack/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func NewServer() *Server {
srv.mux.HandleFunc("/api/groups.create", srv.ServeGroupsCreate)
srv.mux.HandleFunc("/api/team.info", srv.ServeTeamInfo)
// TODO: history, leave, join
srv.mux.HandleFunc("/oauth/authorize", srv.ServeOAuthAuthorize)

srv.mux.HandleFunc("/stats", func(w http.ResponseWriter, req *http.Request) {
srv.state.mx.Lock()
Expand Down
27 changes: 0 additions & 27 deletions devtools/mockslack/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,3 @@ func (st *state) newUser(u User) User {

return u
}

func (st *state) addUserAppScope(userID, clientID string, scopes ...string) string {
st.mx.Lock()
defer st.mx.Unlock()

if st.users[userID].appTokens[clientID] == nil {
tok := &AuthToken{ID: st.gen.UserAccessToken(), User: userID, Scopes: scopes}
st.tokens[tok.ID] = tok
st.users[userID].appTokens[clientID] = tok

code := st.gen.TokenCode()
st.tokenCodes[code] = &tokenCode{AuthToken: tok, ClientID: clientID}
return code
}

tok := st.users[userID].appTokens[clientID]

for _, scope := range scopes {
if !contains(tok.Scopes, scope) {
tok.Scopes = append(tok.Scopes, scope)
}
}

code := st.gen.TokenCode()
st.tokenCodes[code] = &tokenCode{AuthToken: tok, ClientID: clientID}
return code
}
23 changes: 22 additions & 1 deletion devtools/procwrap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"os"
"os/exec"
"os/signal"
"strings"
"sync"
"time"
)
Expand Down Expand Up @@ -68,7 +69,27 @@

func handleStart(w http.ResponseWriter, req *http.Request) {
_ = req.ParseForm()
start(req.Form["extra-arg"])
extraArgs := req.Form["extra-arg"]
if len(extraArgs) == 0 {
start(nil)
return
}

if len(extraArgs) != 2 {
http.Error(w, "invalid extra-arg", http.StatusBadRequest)
return
}
if extraArgs[0] != "--experimental" {
http.Error(w, "invalid extra-arg", http.StatusBadRequest)
return
}
flags := strings.Split(extraArgs[1], ",")
if extraArgs[1] == "" || len(flags) == 0 || len(flags) > 10 {
http.Error(w, "invalid extra-arg", http.StatusBadRequest)
return
}

start([]string{"--experimental", strings.Join(flags, ",")})
}

func handleSignal(w http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -104,7 +125,7 @@
ctx := context.Background()
ctx, cancel = context.WithCancel(ctx)

cmd = exec.CommandContext(ctx, args[0], args[1:]...)

Check failure

Code scanning / CodeQL

Command built from user-controlled sources Critical

This command depends on a
user-provided value
.
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

Expand Down
2 changes: 1 addition & 1 deletion graphql2/mapconfig.go

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

2 changes: 1 addition & 1 deletion schedule/oncallnotificationrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (r *RuleID) UnmarshalText(data []byte) error {
if err != nil {
return err
}
i, err := strconv.ParseInt(string(data[37:]), 10, 64)
i, err := strconv.ParseInt(string(data[37:]), 10, 32)
if err != nil {
return err
}
Expand Down
51 changes: 8 additions & 43 deletions web/src/app/util/query_param.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,23 @@
const quoteRx = (s) => (s || '').replace(/[.?*+^$[\]\\(){}|-]/g, '\\$&')

export function getParameterByName(name, url = global.location.href) {
name = name.replace(/[[\]]/g, '\\$&')
const rx = new RegExp('[?&]' + quoteRx(name) + '(=([^&#]*)|&|#|$)')
const m = rx.exec(url)
if (!m) return null
if (!m[2]) return ''

return decodeURIComponent(m[2].replace(/\+/g, ' '))
return new URL(url).searchParams.get(name)
}

// returns hash of all parameters with keys and values
export function getAllParameters(url = global.location.href) {
// match and select any parameters in the url
const rx = /[?&](\w+)=(?:([^&#]*)|&|#|$)/

const queries = {}
// find the first match
let m = rx.exec(url)
while (m) {
// while we have a match
url = url.replace(m[0], '')
queries[m[1]] = decodeURIComponent(m[2].replace(/\+/g, ' '))
m = rx.exec(url) // find the next match
const q = {}
for (const [key, value] of new URL(url).searchParams) {
q[key] = value
}

return queries
return q
}

// takes in a var name, var value, and optionally a url to read previous params from.
// returns a string of the params and the maintained hash (DOES NOT RETURN THE PATH)
export function setParameterByName(name, value, url = global.location.href) {
// fetch all current url queries
const queries = getAllParameters(url)

// set new value
queries[name] = encodeURIComponent(value)

// rebuild the url -- omit the parameter `name` if value is null
const queryList = Object.keys(queries)
.sort((a, b) => (a < b ? -1 : 1))
.filter((i) => !(value === null && i === name))
.map((query) => {
return query + '=' + queries[query]
})

// match against anything that is after the # in the address
const rx = /(#.*)/
const m = rx.exec(url)
let hash = ''
if (m) hash = m[1]
const newURL = '?' + queryList.join('&') + hash

return newURL
const u = new URL(url)
u.searchParams.set(name, value)
return u.toString()
}

// clears the parameter given from the current url
Expand Down