Skip to content

Protect the members of a collection with a depth 0 WebDAV lock - #1258

Open
arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:webdav-depth0-collection-lock
Open

arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:webdav-depth0-collection-lock

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

A depth 0 write lock on a collection does not prevent other clients from adding or removing its internal members. Without the lock token, PUT and MKCOL create new members and DELETE, MOVE and COPY remove, rename or add members of the locked collection.

RFC 4918, section 7: "Clients MUST submit a lock-token they are authorized to use in any request that modifies a write-locked resource", and for collections this covers "any modification of an internal member URI". Section 7.5 states that a collection write lock, "whether created with a "Depth: 0" or "Depth: infinity" header", protects any request that would create a new resource in the collection, remove an internal member URL or change the segment name of an internal member.

isLocked() only considered ancestor locks with a depth greater than 0. The lock of the direct parent collection is now also checked, whatever its depth, for the requests that change its membership: PUT of a new resource, MKCOL, DELETE, the source of MOVE and the destination of COPY and MOVE.

Tested on a local Tomcat with LOCK /a/ and Depth: 0, requests sent without the lock token:

Request before after
PUT /a/new 201 423
MKCOL /a/sub/ 201 423
DELETE /a/m 204 423
MOVE /a/m to /m2 201 423
MOVE /a/m to /a/m3 201 423
MOVE /out to /a/in 201 423
COPY /out to /a/c 201 423
PUT /a/m (existing member) 204 204
PUT /a/new with If: </a> (<token>) 201 201

httpd mod_dav rejects the same requests. The new test in TestWebdavServlet fails without the change.

A depth 0 write lock on a collection did not prevent other clients from
adding or removing its internal members. Without the lock token, PUT and
MKCOL could create new members, and DELETE, MOVE and COPY could remove,
rename or add members of the locked collection.

RFC 4918, section 7.5 states that a collection write lock, whether depth 0
or depth infinity, protects any request that would create a new resource
in the collection, remove an internal member URL or change the segment
name of an internal member. The lock of the direct parent collection is
now checked for these requests whatever its depth.
} else {
// parentPath == path is a check for the first loop
if (parentPath == path || parentLock.depth > 0) {
if (parentPath == path || parentLock.depth > 0 || directParent) {
if (lock != null) {
// The shared lock might not have the same depth
if (parentPath == path || lock.depth > 0) {
if (parentPath == path || lock.depth > 0 || directParent) {
if (slash < 0) {
break;
}
directParent = memberChange && parentPath == path;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional: parentPath is the same instance as path only on the first iteration, same idiom as the existing checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants