Xuanwo opened a new pull request, #8958:
URL: https://github.com/apache/opendal/pull/8958

   # Which issue does this PR close?
   
   None.
   
   # Rationale for this change
   
   An audit of `opendal-service-webdav` identified five protocol-handling and 
error-mapping defects against RFC 9110 and RFC 4918:
   
   1. **Ranged reads accepted `200 OK` unconditionally and overflowing 
`BytesRange` emitted an empty `Range:` header.** A server that ignores `Range` 
and replies with `200 OK` caused `WebdavReader` to silently return bytes from 
offset 0. Meanwhile, overflowing ranges (where `BytesRange::to_header()` 
returns `""`) were sent with an empty `Range` header instead of failing early 
with `ErrorKind::RangeNotSatisfied`.
   2. **Untrusted `<D:href>` values in `PROPFIND` responses could panic or 
corrupt paths.** `WebdavLister` passed `<D:href>` directly to 
`build_relative_path`, which slices at `root.len()`. Absolute URIs (allowed by 
RFC 4918 ยง8.3, e.g., `https://host/path`), hrefs shorter than `root`, or hrefs 
outside `server_path`/`root` could panic or produce invalid relative paths.
   3. **`ResourceTypeContainer` rejected RFC 4918 extension elements.** 
Modeling `<D:resourcetype>` with `#[serde(rename = "$value")]` over a closed 
single-variant enum caused XML deserialization to fail whenever a server 
returned extension elements such as `<cal:calendar/>`, `<D:principal/>`, or 
`<card:addressbook/>`.
   4. **User-metadata and `PROPPATCH` XML parsers corrupted values and 
swallowed errors.** `parse_user_metadata_from_xml` enabled `trim_text(true)` 
(stripping spaces adjacent to XML entities like `hello &amp; world`), ignored 
numeric character references (`&#10;`, `&#x0A;`), failed to handle default XML 
namespaces, and collected properties from non-2xx `<D:propstat>` blocks (such 
as `404 Not Found`). `check_proppatch_response` broke out of its read loop on 
`Err(_)` and returned `Ok(())`, silently accepting malformed, truncated, or 
status-less `207 Multi-Status` XML.
   5. **`DELETE` rejected RFC-valid `200 OK` / `202 Accepted` responses and 
`parse_error` misclassified `401` and `429`.** `WebdavDeleter` only treated 
`204 No Content` and `404 Not Found` as success, and `parse_error` fell through 
to `ErrorKind::Unexpected` (non-retryable) for both `401 Unauthorized` and `429 
Too Many Requests`.
   
   # What changes are included in this PR?
   
   - **Ranged read validation (`core/services/webdav/src/core.rs`, 
`core/services/webdav/src/reader.rs`):**
     - Return `ErrorKind::RangeNotSatisfied` in `webdav_get` before sending an 
HTTP request when a non-full `BytesRange` produces an empty `Range` header.
     - Reject `200 OK` responses in `WebdavReader::open` unless the requested 
range is the full representation (`0..`) or a prefix/suffix range (`0..N` or 
suffix `N`) whose known `Content-Length` is `<= N`, dropping the unread 
response body without draining it.
   - **Hardened `<D:href>` resolution (`core/services/webdav/src/lister.rs`):**
     - Extract the path component from RFC 4918 absolute `<D:href>` URIs before 
stripping `server_path` on a segment boundary, percent-decoding, and safely 
checking the `root` prefix (returning `ErrorKind::Unexpected` instead of 
panicking on malformed or out-of-root hrefs).
   - **Extensible `<D:resourcetype>` deserialization 
(`core/services/webdav/src/core.rs`):**
     - Replace the closed `$value` enum on `ResourceTypeContainer` with an 
optional `collection` field so unknown RFC 4918 extension elements are ignored 
while collections still map to `EntryMode::DIR` and non-collections to 
`EntryMode::FILE`.
   - **Namespace-aware XML parsing (`core/services/webdav/src/core.rs`):**
     - Rewrite `parse_user_metadata_from_xml` with `quick_xml::NsReader` 
without `trim_text(true)`, decoding both named and numeric character 
references, honoring default and scoped XML namespaces, and collecting 
properties only from `2xx` `<D:propstat>` blocks of the first `<D:response>`.
     - Rewrite `check_proppatch_response` with `quick_xml::NsReader` to fail 
with `ErrorKind::Unexpected` on XML parse errors, truncated documents, missing 
or empty `<D:status>` elements, unparseable status lines, or any non-2xx 
`<D:status>`.
   - **Delete status handling and HTTP error mapping 
(`core/services/webdav/src/deleter.rs`, `core/services/webdav/src/core.rs`):**
     - Accept `200 OK` and `202 Accepted` alongside `204 No Content` and 
unconditional `404 Not Found` in `WebdavDeleter`.
     - Map `401 Unauthorized` to permanent `ErrorKind::PermissionDenied` and 
`429 Too Many Requests` to temporary (retryable) `ErrorKind::RateLimited` in 
`parse_error`.
   - **Tests:**
     - Add deterministic unit tests with mock `HttpTransport` and XML fixtures 
covering all five fixes, and verify against the local 
`fixtures/webdav/dav-server` behavior test suite.
   
   # Are there any user-facing changes?
   
   - Ranged WebDAV reads now return `ErrorKind::Unexpected` instead of silently 
returning data from offset 0 when a server ignores `Range` with `200 OK`, and 
return `ErrorKind::RangeNotSatisfied` for overflowing `BytesRange` inputs.
   - Listing directories containing RFC 4918 extension resource types or 
absolute `<D:href>` URIs now succeeds, while malformed or out-of-root 
`<D:href>` entries return `ErrorKind::Unexpected` instead of panicking.
   - User metadata parsing preserves whitespace around XML entities, decodes 
numeric character references, supports default namespaces, and excludes non-2xx 
`propstat` entries; malformed `PROPPATCH` responses now fail instead of 
succeeding silently.
   - `DELETE` now accepts `200 OK` and `202 Accepted`, `401 Unauthorized` maps 
to `ErrorKind::PermissionDenied`, and `429 Too Many Requests` maps to temporary 
`ErrorKind::RateLimited`.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi
   - Model: Gemini 4 Neon
   - Effort: high
   - Role: Audited `core/services/webdav` against the reported findings, 
implemented the five fixes and deterministic unit tests, and verified 
formatting, clippy, unit tests, rustdoc, and `dav-server` WebDAV behavior tests 
locally. Behavior against external WebDAV servers that emit custom extension 
resource types or non-204 delete responses was verified via mock 
`HttpTransport` and XML fixtures rather than live third-party deployments.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to