Use random job and snapshot IDs
Timestamp-derived IDs were guessable, and the ID is what grants access to indexed source. crypto/rand.Text gives 26 base32 characters.
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/rand"
|
||||||
"embed"
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
@@ -19,7 +20,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
@@ -620,10 +620,9 @@ func safeRelativePath(value string) (string, bool) {
|
|||||||
return filepath.Join(clean...), true
|
return filepath.Join(clean...), true
|
||||||
}
|
}
|
||||||
|
|
||||||
var idCounter atomic.Uint64
|
// uniqueID is unguessable: IDs are the capability that grants access to a job or snapshot.
|
||||||
|
|
||||||
func uniqueID(prefix string) string {
|
func uniqueID(prefix string) string {
|
||||||
return fmt.Sprintf("%s-%x%x", prefix, time.Now().UnixNano(), idCounter.Add(1))
|
return prefix + "-" + rand.Text()
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeError(w http.ResponseWriter, status int, message string) {
|
func writeError(w http.ResponseWriter, status int, message string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user