Skip to content

Commit d0a4e7a

Browse files
committed
fix: added checks for max graffiti size
1 parent f698e55 commit d0a4e7a

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

backend/pkg/api/data_access/search.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ func (d *DataAccessService) GetSearchValidatorsByWithdrawalEnsName(ctx context.C
100100

101101
func (d *DataAccessService) GetSearchValidatorsByGraffiti(ctx context.Context, chainId uint64, graffiti string) (*t.SearchValidatorsByGraffiti, error) {
102102
// TODO: implement handling of chainid
103+
graffitiHex := [32]byte{}
104+
copy(graffitiHex[:], graffiti)
103105
ret := &t.SearchValidatorsByGraffiti{
104106
Graffiti: graffiti,
105-
Hex: hexutil.Encode([]byte(graffiti)),
107+
Hex: hexutil.Encode(graffitiHex[:]),
106108
}
107109
err := db.ReaderDb.GetContext(ctx, &ret.Count, "select count(distinct proposer) from blocks where graffiti_text = $1;", graffiti)
108110
if err != nil {

backend/pkg/api/handlers/input_validation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ var (
3434
reEthereumAddress = regexp.MustCompile(`^(0x)?[0-9a-fA-F]{40}$`)
3535
reWithdrawalCredential = regexp.MustCompile(`^(0x0[01])?[0-9a-fA-F]{62}$`)
3636
reEnsName = regexp.MustCompile(`^.+\.eth$`)
37-
reGraffiti = regexp.MustCompile(`^.{2,}$`) // at least 2 characters, so that queries won't time out
38-
reGraffitiHex = regexp.MustCompile(`^(0x)?([0-9a-fA-F]{2}){2,}$`) // at least 2 bytes, so that queries won't time out
39-
reCursor = regexp.MustCompile(`^[A-Za-z0-9-_]+$`) // has to be base64
37+
reGraffiti = regexp.MustCompile(`^.{2,32}$`) // at least 2 characters, so that queries won't time out
38+
reGraffitiHex = regexp.MustCompile(`^(0x)?([0-9a-fA-F]{2}){32}$`)
39+
reCursor = regexp.MustCompile(`^[A-Za-z0-9-_]+$`) // has to be base64
4040
reEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
4141
rePassword = regexp.MustCompile(`^.{5,}$`)
4242
reEmailUserToken = regexp.MustCompile(`^[a-z0-9]{40}$`)

backend/pkg/api/handlers/search.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ func (h *HandlerService) handleSearchValidatorsByWithdrawalEnsName(ctx context.C
274274
}
275275

276276
func (h *HandlerService) handleSearchValidatorsByGraffiti(ctx context.Context, input string, chainId uint64) (*types.SearchResult, error) {
277+
// regex could only verify max character length, validate max byte length here
278+
if len(input) > 32 {
279+
return nil, nil // return no error as to not disturb the other search types
280+
}
277281
result, err := h.daService.GetSearchValidatorsByGraffiti(ctx, chainId, input)
278282
return asSearchResult(validatorsByGraffiti, chainId, result, err)
279283
}

0 commit comments

Comments
 (0)