Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random string function should only contains letters #1906

Merged
merged 1 commit into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/nginx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"encoding/json"
"fmt"
"math/rand"
"net"
"net/http"
"net/http/pprof"
Expand Down Expand Up @@ -47,6 +48,8 @@ import (
)

func main() {
rand.Seed(time.Now().UnixNano())

fmt.Println(version.String())

showVersion, conf, err := parseFlags()
Expand Down
27 changes: 14 additions & 13 deletions internal/ingress/controller/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ limitations under the License.
package template

import (
"crypto/rand"
"encoding/base64"
"encoding/json"
"fmt"
"math/rand"
"net"
"net/url"
"os"
"os/exec"
"strconv"
"strings"
text_template "text/template"
"time"

"github.com/golang/glog"
"github.com/pkg/errors"
Expand Down Expand Up @@ -493,12 +494,7 @@ func buildDenyVariable(a interface{}) string {
}

if _, ok := denyPathSlugMap[l]; !ok {
s, err := randomString()
if err != nil {
return ""
}

denyPathSlugMap[l] = s
denyPathSlugMap[l] = randomString()
}

return fmt.Sprintf("$deny_%v", denyPathSlugMap[l])
Expand Down Expand Up @@ -693,12 +689,17 @@ func buildAuthSignURL(input interface{}) string {
return fmt.Sprintf("%v&rd=$pass_access_scheme://$http_host$request_uri", s)
}

func randomString() (string, error) {
b := make([]byte, 16)
_, err := rand.Read(b)
if err != nil {
return "", err
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func init() {
rand.Seed(time.Now().UnixNano())
}

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)
}