Sahana2524 opened a new pull request, #425:
URL: https://github.com/apache/commons-net/pull/425

   `DotTerminatedMessageWriter` (the writer returned by 
`SMTPClient.sendMessageData()` and 
`NNTPClient.postArticle()`/`forwardArticle()`) turns a lone LF into CRLF, but a 
lone CR is written through as is and leaves the writer in `LAST_WAS_CR_STATE`, 
so a period right after it is not doubled. A body containing CR `.` CR LF 
therefore goes out as `<CR>.<CR><LF>`.
   
   A receiver that only ends lines on CRLF reads that as text, but some treat a 
lone CR as a line break (Cisco Secure Email's default "clean" bare CR/LF 
handling rewrites it to CRLF, for example). Those see a line holding a single 
dot and end DATA there, so whatever follows in the body is run as SMTP commands 
on the client's session. This is the end-of-data ambiguity behind SMTP 
smuggling (CERT/CC VU#302671). Message bodies are often built from end-user 
input, and a body such as
   
   ```java
   "Hello\r.\r\nMAIL FROM:<[email protected]>\r\nRCPT 
TO:<[email protected]>\r\nDATA\r\n..."
   ```
   
   is currently written unchanged. With this change it becomes 
`Hello\r\n..\r\nMAIL FROM:...`, which every receiver reads as body text. NNTP 
posts go through the same writer.
   
   The fix completes a lone CR to CRLF when the next character arrives, which 
is what the writer already does for a lone LF and what `close()` already does 
for a trailing CR. RFC 5321 section 2.3.8 only allows CR as part of CRLF, so 
CRLF and LF input is written exactly as before. The one visible difference is 
that a lone CR inside a body now becomes a line break instead of being sent 
raw. That seemed the safer reading to me, but I'm happy to switch to only 
doubling the dot after a lone CR if you'd rather keep bare CRs on the wire. 
This is separate from #398, which handled the first line of the message.
   
   The new `DotTerminatedMessageWriterTest` case fails on master and passes 
with this change. `mvn` (default goal, with `-Ddoclint=all` as in CI) passes 
locally on Java 21.
   
   - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
   - [x] Read the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use 
Artificial Intelligence (AI).
   - [x] I used AI to create any part of, or all of, this pull request. Which 
AI tool was used to create this pull request, and to what extent did it 
contribute?
   - [x] Run a successful build using the default 
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command 
line by itself.
   - [x] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied. This may not always be possible, 
but it is a best practice.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body. Note that a maintainer may squash commits during the merge process.
   


-- 
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