Restrict allowed characters in transaction IDs

This commit is contained in:
Alan Bernstein 2020-07-10 17:58:47 -05:00
parent a947bc8ad9
commit 7c37ececfd
2 changed files with 8 additions and 2 deletions

View file

@ -53,8 +53,7 @@ var (
ErrInvalidView = errors.New("invalid view")
ErrInvalidCacheType = errors.New("invalid cache type")
ErrName = errors.New("invalid index or field name, must match [a-z][a-z0-9_-]* and contain at most 230 characters")
ErrLabel = errors.New("invalid row or column label, must match [A-Za-z0-9_-]")
ErrName = errors.New("invalid index or field name, must match [a-z][a-z0-9_-]* and contain at most 230 characters")
// ErrFragmentNotFound is returned when a fragment does not exist.
ErrFragmentNotFound = errors.New("fragment not found")

View file

@ -17,6 +17,7 @@ package pilosa
import (
"context"
"encoding/json"
"regexp"
"sync"
"time"
@ -24,6 +25,8 @@ import (
"github.com/pkg/errors"
)
var txIDRegexp = regexp.MustCompile("^[A-Za-z0-9_-]$")
// Transaction contains information related to a block of work that
// needs to be tracked and spans multiple API calls.
type Transaction struct {
@ -93,6 +96,10 @@ func (tm *TransactionManager) Start(ctx context.Context, id string, timeout time
tm.mu.Lock()
defer tm.mu.Unlock()
if !txIDRegexp.Match([]byte(id)) {
return nil, errors.New("invalid transaction ID, must match [A-Za-z0-9_-]")
}
trnsMap, err := tm.store.List()
if err != nil {
return nil, errors.Wrap(err, "listing transactions in Start")