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

Do not Escape HTML when encode the cloudfront sign policy #2164

Merged
merged 6 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 1 addition & 3 deletions service/cloudfront/sign/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"crypto/rsa"
"crypto/sha1"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/url"
Expand Down Expand Up @@ -169,11 +168,10 @@ func NewCannedPolicy(resource string, expires time.Time) *Policy {

// encodePolicy encodes the Policy as JSON and also base 64 encodes it.
func encodePolicy(p *Policy) (b64Policy, jsonPolicy []byte, err error) {
jsonPolicy, err = json.Marshal(p)
jsonPolicy, err = encodePolicyJSON(p)
if err != nil {
return nil, nil, fmt.Errorf("failed to encode policy, %s", err.Error())
}

// Remove leading and trailing white space, JSON encoding will note include
// whitespace within the encoding.
jsonPolicy = bytes.TrimSpace(jsonPolicy)
Expand Down
11 changes: 11 additions & 0 deletions service/cloudfront/sign/policy_json_1_6.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !go1.7

package sign

import (
"encoding/json"
)

func encodePolicyJSON(p *Policy) ([]byte, error) {
return json.Marshal(p)
}
16 changes: 16 additions & 0 deletions service/cloudfront/sign/policy_json_1_7.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// +build go1.7

package sign

import (
"bytes"
"encoding/json"
)

func encodePolicyJSON(p *Policy) ([]byte, error) {
buffer := &bytes.Buffer{}
encoder := json.NewEncoder(buffer)
encoder.SetEscapeHTML(false)
err := encoder.Encode(p)
return buffer.Bytes(), err
}