Random string function should only contains letters (#1906)
This commit is contained in:
parent
b0e0712984
commit
3e7d1f9acf
2 changed files with 17 additions and 13 deletions
|
@ -19,6 +19,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/pprof"
|
"net/http/pprof"
|
||||||
|
@ -47,6 +48,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
fmt.Println(version.String())
|
fmt.Println(version.String())
|
||||||
|
|
||||||
showVersion, conf, err := parseFlags()
|
showVersion, conf, err := parseFlags()
|
||||||
|
|
|
@ -17,10 +17,10 @@ limitations under the License.
|
||||||
package template
|
package template
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -28,6 +28,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
text_template "text/template"
|
text_template "text/template"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -493,12 +494,7 @@ func buildDenyVariable(a interface{}) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := denyPathSlugMap[l]; !ok {
|
if _, ok := denyPathSlugMap[l]; !ok {
|
||||||
s, err := randomString()
|
denyPathSlugMap[l] = randomString()
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
denyPathSlugMap[l] = s
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("$deny_%v", denyPathSlugMap[l])
|
return fmt.Sprintf("$deny_%v", denyPathSlugMap[l])
|
||||||
|
@ -693,12 +689,17 @@ func buildAuthSignURL(input interface{}) string {
|
||||||
return fmt.Sprintf("%v&rd=$pass_access_scheme://$http_host$request_uri", s)
|
return fmt.Sprintf("%v&rd=$pass_access_scheme://$http_host$request_uri", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func randomString() (string, error) {
|
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||||
b := make([]byte, 16)
|
|
||||||
_, err := rand.Read(b)
|
func init() {
|
||||||
if err != nil {
|
rand.Seed(time.Now().UnixNano())
|
||||||
return "", err
|
}
|
||||||
|
|
||||||
|
func randomString() string {
|
||||||
|
b := make([]rune, 32)
|
||||||
|
for i := range b {
|
||||||
|
b[i] = letters[rand.Intn(len(letters))]
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(b), nil
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue