Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
655f0dd
Route GitHub Issues notifications to commits@ instead of dev@
arturobernalg Nov 25, 2026
393f884
Fix mailing list domain in notifications.issues
arturobernalg Nov 25, 2026
a6a2713
Point notifications.issues at the new notifications@ list
arturobernalg Nov 25, 2026
ef4fd79
Re-save .asf.yaml to re-trigger notifications validation
arturobernalg Nov 26, 2026
adf3331
Temporarily revert .asf.yaml notifications::issues to [email protected]
arturobernalg Nov 26, 2026
2f22ea5
Restore .asf.yaml notifications::issues to [email protected]
arturobernalg Nov 26, 2026
782dbd4
Add RFC6724-based DNS resolver with configurable family preference.
arturobernalg Jan 9, 2026
f7aaa5e
Implement true INTERLEAVE ordering.
arturobernalg Jan 13, 2026
f0de6cf
Apply RFC 6724 destination ordering and family preferences to DNS res…
arturobernalg Jan 15, 2026
ed522f6
Stagger connection attempts across resolved addresses (RFC 8305)
arturobernalg Nov 10, 2026
5b98377
Race connection attempts across resolved addresses for the Classic cl…
arturobernalg Nov 10, 2026
2a78479
Skip malformed auth challenge headers instead of dropping all of them
shinseongsu Nov 30, 2026
527490d
Bump the all group with 10 updates
dependabot[bot] Dec 1, 2026
c04c9a3
Bump actions/setup-java from 5.6.0 to 6.3.0
dependabot[bot] Dec 1, 2026
ba37c09
Close proxy connection when error response consumption fails
Aayush10016 Dec 4, 2026
5e4c419
Do not quote the filename* parameter in multipart Content-Disposition
shinseongsu Dec 3, 2026
a948321
Redesign of the request retry strategy
ok2c Nov 30, 2026
f9da842
restrict cache file mode and reject symlinks in FileResourceFactory (…
Hsnmohd Dec 5, 2026
f00cd97
HTTPCLIENT-2436: Fall back to remaining addresses after a TLS failure…
arturobernalg Dec 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .asf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# specific language governing permissions and limitations
# under the License.

notifications:
issues: [email protected]

github:
features:
issues: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ jobs:
esac
- name: Set up toolchain JDK ${{ matrix.java }}
id: setup-java-toolchain
uses: actions/setup-java@v5.6.0
uses: actions/setup-java@v6.3.0
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
- name: Set up JDK 17 for Maven
uses: actions/setup-java@v5.6.0
uses: actions/setup-java@v6.3.0
with:
distribution: 'temurin'
java-version: '17'
Expand Down
4 changes: 2 additions & 2 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
wrapperVersion=3.3.4
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.10.0/apache-maven-3.10.0-bin.zip
distributionSha256Sum=1f6d9909266510f039f59aa0e13dcd2c66da85f043e56276e41f2918f8bddaff
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.10.2/apache-maven-3.10.2-bin.zip
distributionSha256Sum=7d69999d218e025cf1c14691ba748a09706e47999bd505009403cef9d757c2df
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@
package org.apache.hc.client5.http.impl.cache;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.channels.Channels;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermissions;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.EnumSet;
import java.util.Set;

import org.apache.hc.client5.http.cache.Resource;
import org.apache.hc.client5.http.cache.ResourceFactory;
Expand All @@ -49,6 +59,21 @@
@Contract(threading = ThreadingBehavior.STATELESS)
public class FileResourceFactory implements ResourceFactory {

/**
* Permissions of the cache files created by this factory. A cache file holds a response
* body verbatim, so it must not be readable by other users of the system. Empty on file
* systems without POSIX file permissions, where the file inherits the directory's ACL.
*/
private static final FileAttribute<?>[] OWNER_ONLY = ownerOnlyAttributes();

/**
* Cache files are always created anew. {@code CREATE_NEW} fails if anything, including a
* symbolic link, exists at the path, so a write can never land in a file this factory did
* not create.
*/
private static final Set<? extends OpenOption> CREATE_EXCLUSIVE =
EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);

private final File cacheDir;

public FileResourceFactory(final File cacheDir) {
Expand Down Expand Up @@ -87,16 +112,36 @@ public Resource generate(
Args.notNull(requestId, "Request id");
final String filename = generateUniqueCacheFileName(requestId, eTag, content, off, len);
final File file = new File(cacheDir, filename);
try (FileOutputStream outStream = new FileOutputStream(file, false)) {
if (content != null) {
outStream.write(content, off, len);
}
try {
writeCacheFile(file.toPath(), content, off, len);
} catch (final IOException ex) {
throw new ResourceIOException(ex.getMessage(), ex);
}
return new FileResource(file);
}

private static FileAttribute<?>[] ownerOnlyAttributes() {
if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
return new FileAttribute<?>[] {
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-------")) };
}
return new FileAttribute<?>[0];
}

private static void writeCacheFile(
final Path file, final byte[] content, final int off, final int len) throws IOException {
// Whatever is at the path is not reused: a pre-existing file keeps its own mode and may be
// a hard link to a file outside the cache directory. Remove it (a symbolic link is removed,
// not followed) and create the cache file exclusively with owner-only permissions.
Files.deleteIfExists(file);
try (OutputStream outStream = Channels.newOutputStream(
Files.newByteChannel(file, CREATE_EXCLUSIVE, OWNER_ONLY))) {
if (content != null) {
outStream.write(content, off, len);
}
}
}

@Override
public Resource generate(final String requestId, final byte[] content, final int off, final int len) throws ResourceIOException {
if (content != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@
package org.apache.hc.client5.http.impl.cache;


import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermissions;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

class TestFileResourceFactory {

Expand Down Expand Up @@ -66,4 +74,80 @@ void testViaValueLookup() throws Exception {
FileResourceFactory.generateUniqueCacheFileName(requestId, null, null, 0, 0));
}

@Test
void testGeneratedCacheFileIsOwnerOnly(@TempDir final Path cacheDir) throws Exception {
Assumptions.assumeTrue(FileSystems.getDefault().supportedFileAttributeViews().contains("posix"));
final String requestId = keyGenerator.generateKey(new URI("http://localhost/stuff"));
final byte[] content = "secret".getBytes(StandardCharsets.US_ASCII);

new FileResourceFactory(cacheDir.toFile()).generate(requestId, "\"v1\"", content, 0, content.length);

final Path file = cacheDir.resolve(
FileResourceFactory.generateUniqueCacheFileName(requestId, "\"v1\"", content, 0, content.length));
Assertions.assertEquals("rw-------",
PosixFilePermissions.toString(Files.getPosixFilePermissions(file)));
}

@Test
void testGenerateDoesNotFollowSymlink(@TempDir final Path cacheDir, @TempDir final Path otherDir) throws Exception {
final String requestId = keyGenerator.generateKey(new URI("http://localhost/stuff"));
final byte[] content = "response body".getBytes(StandardCharsets.US_ASCII);
final Path outside = otherDir.resolve("outside");
Files.write(outside, "untouched".getBytes(StandardCharsets.US_ASCII));
final Path link = cacheDir.resolve(
FileResourceFactory.generateUniqueCacheFileName(requestId, "\"v1\"", content, 0, content.length));
try {
Files.createSymbolicLink(link, outside);
} catch (final IOException | UnsupportedOperationException ex) {
Assumptions.abort("symbolic links are not supported here");
}

new FileResourceFactory(cacheDir.toFile()).generate(requestId, "\"v1\"", content, 0, content.length);

Assertions.assertEquals("untouched",
new String(Files.readAllBytes(outside), StandardCharsets.US_ASCII));
Assertions.assertFalse(Files.isSymbolicLink(link));
Assertions.assertEquals("response body",
new String(Files.readAllBytes(link), StandardCharsets.US_ASCII));
}

@Test
void testGenerateReplacesPreexistingFile(@TempDir final Path cacheDir) throws Exception {
Assumptions.assumeTrue(FileSystems.getDefault().supportedFileAttributeViews().contains("posix"));
final String requestId = keyGenerator.generateKey(new URI("http://localhost/stuff"));
final byte[] content = "secret".getBytes(StandardCharsets.US_ASCII);
final Path file = cacheDir.resolve(
FileResourceFactory.generateUniqueCacheFileName(requestId, "\"v1\"", content, 0, content.length));
Files.write(file, "planted".getBytes(StandardCharsets.US_ASCII));
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("rw-rw-rw-"));

new FileResourceFactory(cacheDir.toFile()).generate(requestId, "\"v1\"", content, 0, content.length);

Assertions.assertEquals("rw-------",
PosixFilePermissions.toString(Files.getPosixFilePermissions(file)));
Assertions.assertEquals("secret", new String(Files.readAllBytes(file), StandardCharsets.US_ASCII));
}

@Test
void testGenerateDoesNotWriteThroughHardLink(@TempDir final Path cacheDir, @TempDir final Path otherDir) throws Exception {
final String requestId = keyGenerator.generateKey(new URI("http://localhost/stuff"));
final byte[] content = "response body".getBytes(StandardCharsets.US_ASCII);
final Path outside = otherDir.resolve("outside");
Files.write(outside, "untouched".getBytes(StandardCharsets.US_ASCII));
final Path link = cacheDir.resolve(
FileResourceFactory.generateUniqueCacheFileName(requestId, "\"v1\"", content, 0, content.length));
try {
Files.createLink(link, outside);
} catch (final IOException | UnsupportedOperationException ex) {
Assumptions.abort("hard links are not supported here");
}

new FileResourceFactory(cacheDir.toFile()).generate(requestId, "\"v1\"", content, 0, content.length);

Assertions.assertEquals("untouched",
new String(Files.readAllBytes(outside), StandardCharsets.US_ASCII));
Assertions.assertEquals("response body",
new String(Files.readAllBytes(link), StandardCharsets.US_ASCII));
}

}
Loading
Loading