Skip to content

Commit

Permalink
be defensive about wrongly quoted etags
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Jul 7, 2021
1 parent 54e2236 commit 75f4331
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/more-robust-etag-handling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Be defensive about wrongly quoted etags

When ocdav renders etags it will now try to correct them to the definition as *quoted strings* which do not contain `"`. This prevents double or triple quoted etags on the webdav api.

https://github.com/cs3org/reva/pull/1870
12 changes: 10 additions & 2 deletions internal/http/services/owncloud/ocdav/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
// etags must be enclosed in double quotes and cannot contain them.
// See https://tools.ietf.org/html/rfc7232#section-2.3 for details
// TODO(jfd) handle weak tags that start with 'W/'
propstatOK.Prop = append(propstatOK.Prop, s.newProp("d:getetag", md.Etag))
propstatOK.Prop = append(propstatOK.Prop, s.newProp("d:getetag", quoteEtag(md.Etag)))
}

if md.PermissionSet != nil {
Expand Down Expand Up @@ -698,7 +698,7 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
switch pf.Prop[i].Local {
case "getetag": // both
if md.Etag != "" {
propstatOK.Prop = append(propstatOK.Prop, s.newProp("d:getetag", md.Etag))
propstatOK.Prop = append(propstatOK.Prop, s.newProp("d:getetag", quoteEtag(md.Etag)))
} else {
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("d:getetag", ""))
}
Expand Down Expand Up @@ -802,6 +802,14 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
return &response, nil
}

// be defensive about wrong encoded etags
func quoteEtag(etag string) string {
if strings.HasPrefix(etag, "W/") {
return `W/"` + strings.Trim(etag[2:], `"`) + `"`
}
return `"` + strings.Trim(etag, `"`) + `"`
}

// a file is only yours if you are the owner
func isCurrentUserOwner(ctx context.Context, owner *userv1beta1.UserId) bool {
contextUser, ok := ctxuser.ContextGetUser(ctx)
Expand Down

0 comments on commit 75f4331

Please sign in to comment.