Skip to content

Commit

Permalink
Adding padding to base64 encoded policy decisions (#1738)
Browse files Browse the repository at this point in the history
Switching to standard encoding

Signed-off-by: Matthew A Johnson <matjoh@microsoft.com>
  • Loading branch information
matajoh committed Apr 20, 2023
1 parent 1143934 commit d816cbe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/securitypolicy/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func ExtractPolicyDecision(errorMessage string) (string, error) {
return "", errors.Errorf("unable to extract policy decision from error message: %s", errorMessage)
}

errorBytes, err := base64.RawURLEncoding.DecodeString(matches[1])
errorBytes, err := base64.StdEncoding.DecodeString(matches[1])
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/securitypolicy/securitypolicyenforcer_rego.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (policy *regoEnforcer) policyDecisionToError(ctx context.Context, decision

log.G(ctx).WithField("policyDecision", string(decisionJSON))

base64EncodedDecisionJSON := base64.RawURLEncoding.EncodeToString(decisionJSON)
base64EncodedDecisionJSON := base64.StdEncoding.EncodeToString(decisionJSON)
errorMessage := fmt.Errorf(policyDecisionPattern, base64EncodedDecisionJSON)
if policy.maxErrorMessageLength == 0 {
// indicates no message truncation
Expand All @@ -373,7 +373,7 @@ func (policy *regoEnforcer) policyDecisionToError(ctx context.Context, decision
log.G(ctx).WithError(err).Error("unable to marshal error object")
decisionJSON = []byte(`"Unable to marshal error object"`)
}
base64EncodedDecisionJSON = base64.RawURLEncoding.EncodeToString(decisionJSON)
base64EncodedDecisionJSON = base64.StdEncoding.EncodeToString(decisionJSON)
errorMessage = fmt.Errorf(policyDecisionPattern, base64EncodedDecisionJSON)

if len(errorMessage.Error()) <= policy.maxErrorMessageLength {
Expand Down

0 comments on commit d816cbe

Please sign in to comment.