mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-08-04 14:46:03 +00:00
Restrict echo to only allow characters 0-9
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
This commit is contained in:
parent
4dd3156ca7
commit
9dca948e9b
3 changed files with 386 additions and 160 deletions
|
|
@ -562,7 +562,7 @@ func drain_potential_tty_garbage(term *tty.Term) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
canary, err := secrets.TokenHex()
|
||||
canary, err := secrets.TokenAlphabet(secrets.DEFAULT_NUM_OF_BYTES_FOR_TOKEN, "0123456789")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
502
kitty/window.py
502
kitty/window.py
File diff suppressed because it is too large
Load diff
|
|
@ -6,6 +6,7 @@ import (
|
|||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/emmansun/base64"
|
||||
)
|
||||
|
|
@ -14,6 +15,39 @@ var _ = fmt.Print
|
|||
|
||||
const DEFAULT_NUM_OF_BYTES_FOR_TOKEN = 32
|
||||
|
||||
func encode_bytes(input []byte, alphabet string) string {
|
||||
if len(input) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
base := big.NewInt(int64(len(alphabet)))
|
||||
num := new(big.Int).SetBytes(input)
|
||||
mod := new(big.Int)
|
||||
|
||||
var result []byte
|
||||
|
||||
// Convert the large integer into the custom base system
|
||||
for num.Sign() > 0 {
|
||||
num.DivMod(num, base, mod)
|
||||
result = append(result, alphabet[mod.Int64()])
|
||||
}
|
||||
|
||||
// Preserve leading zeros from the original byte slice
|
||||
for _, b := range input {
|
||||
if b != 0x00 {
|
||||
break
|
||||
}
|
||||
result = append(result, alphabet[0])
|
||||
}
|
||||
|
||||
// Reverse the result slice since DivMod extracts digits backward
|
||||
for i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 {
|
||||
result[i], result[j] = result[j], result[i]
|
||||
}
|
||||
|
||||
return string(result)
|
||||
}
|
||||
|
||||
func TokenBytes(nbytes ...int) ([]byte, error) {
|
||||
if len(nbytes) == 0 {
|
||||
nbytes = []int{DEFAULT_NUM_OF_BYTES_FOR_TOKEN}
|
||||
|
|
@ -41,3 +75,11 @@ func TokenBase64(nbytes ...int) (string, error) {
|
|||
}
|
||||
return base64.StdEncoding.EncodeToString(b), nil
|
||||
}
|
||||
|
||||
func TokenAlphabet(nbytes int, alphabet string) (string, error) {
|
||||
b, err := TokenBytes(nbytes)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return encode_bytes(b, alphabet), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue