mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
The npm republish guard's lenient-scan fallback (for a readme over the strict parser's string-length limit) only extracted version names for the Archived/Disposed check, leaving readmeByVersion empty; forwardSpooled's post-write bookkeeping (byte accounting, readme capture, and the redispose-protection call) keys off that map, so a version going through this fallback silently skipped all of it. The lenient envelope now populates the full guard input. A PyPI upload with no version form field skipped both the filename-vs-field check and the Archived/Disposed guard outright, since neither had a coordinate to check (hectorvent's follow-up on #6435). pypiserver trusts the uploaded filename over the form regardless, so a missing field now falls back to matching the filename against any version of the package that currently carries a status override before letting the upload through.
This commit is contained in:
1 parent
932af22f4a
commit
413bb884aa
7 files changed
+305
-21
No files matched your search
+43
@@ -460,6 +460,49 @@ class CodeArtifactNpmDataPlaneTest {
|
||||
assertEquals(false, upstreamReceivedPut.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Raised by Greptile's review of the fix above: the guard passing is not the whole story.
|
||||
* {@link CodeArtifactNpmDataPlane#forwardSpooled}'s own post-write bookkeeping, including the
|
||||
* override-clearing call that undoes a concurrent dispose racing this exact write (see
|
||||
* {@code CodeArtifactService#forgetContainerBackedStatusOverrideIfUnchanged}'s own javadoc),
|
||||
* keys entirely off {@code readmeByVersion}. An earlier version of this fix left that map
|
||||
* empty for the oversized-readme fallback, which let the guard run but then skipped every one
|
||||
* of those for whichever version it let through, the exact gap a concurrent dispose could
|
||||
* still exploit afterward. This version's own forward must still reach that bookkeeping.
|
||||
*/
|
||||
@Test
|
||||
void aPublishWhoseReadmeOverflowsTheStrictScanStillRunsPostWriteBookkeeping() throws Exception {
|
||||
upstream = vertx.createHttpServer()
|
||||
.requestHandler(request -> request.response().setStatusCode(201).end())
|
||||
.listen(0, "127.0.0.1")
|
||||
.toCompletionStage().toCompletableFuture().get(2, TimeUnit.SECONDS);
|
||||
|
||||
CodeArtifactService service = mock(CodeArtifactService.class);
|
||||
when(service.resolveAuthorizationToken("good-token", DOMAIN))
|
||||
.thenReturn(Optional.of(new AuthorizationTokenScope("000000000000", "us-east-1")));
|
||||
when(service.ensureFormatContainerId("npm", "us-east-1", DOMAIN, "000000000000", REPOSITORY))
|
||||
.thenReturn(NPM_REPOSITORY_ID);
|
||||
VerdaccioSidecarClient verdaccioClient = mock(VerdaccioSidecarClient.class);
|
||||
when(verdaccioClient.ensureReady(eq(NPM_REPOSITORY_ID), anyString()))
|
||||
.thenReturn("http://127.0.0.1:" + upstream.actualPort());
|
||||
startDataPlane(service, verdaccioClient);
|
||||
|
||||
byte[] content = "fresh bytes".getBytes(StandardCharsets.UTF_8);
|
||||
String oversizedReadme = "x".repeat(1_000_001);
|
||||
String envelope = "{\"name\":\"my-pkg\",\"versions\":{\"1.0.0\":{\"name\":\"my-pkg\",\"version\":\"1.0.0\","
|
||||
+ "\"readme\":\"" + oversizedReadme + "\",\"dist\":{\"tarball\":\"http://ignored/my-pkg-1.0.0.tgz\","
|
||||
+ "\"integrity\":\"" + integrity(content) + "\"}}},\"_attachments\":{\"my-pkg-1.0.0.tgz\":{"
|
||||
+ "\"content_type\":\"application/octet-stream\",\"data\":\""
|
||||
+ Base64.getEncoder().encodeToString(content) + "\",\"length\":" + content.length + "}}}";
|
||||
|
||||
HttpResponse response = put("/codeartifact/npm/" + DOMAIN + "/" + REPOSITORY + "/my-pkg", "good-token",
|
||||
envelope);
|
||||
|
||||
assertEquals(201, response.statusCode());
|
||||
verify(service).forgetContainerBackedStatusOverrideIfUnchanged(eq("us-east-1"), eq(DOMAIN),
|
||||
eq("000000000000"), eq(REPOSITORY), eq("npm"), isNull(), eq("my-pkg"), eq("1.0.0"), isNull());
|
||||
}
|
||||
|
||||
/**
|
||||
* The identity used to look up an existing match comes from the URL the publish was sent to,
|
||||
* not the envelope's own {@code name} field. A mismatched body must not be checked against
|
||||
|
||||
+61
@@ -15,6 +15,7 @@ import java.net.InetSocketAddress;
|
||||
import java.net.http.HttpClient;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -435,6 +436,66 @@ class CodeArtifactPypiControllerTest {
|
||||
anyLong(), anyLong());
|
||||
}
|
||||
|
||||
/**
|
||||
* hectorvent's follow-up on this PR: a missing version field must not let an upload of an
|
||||
* Archived/Disposed version through just because there is no explicit coordinate to check.
|
||||
* The uploaded filename itself names version 1.0.0, which this package's only override marks
|
||||
* Disposed, so the guard must still fire even though the form carries no version field at all.
|
||||
*/
|
||||
@Test
|
||||
void uploadWithNoVersionFieldStillRejectsAFilenameNamingAnArchivedOrDisposedVersion() {
|
||||
AtomicBoolean uploadReceived = new AtomicBoolean();
|
||||
backend.createContext("/simple/my-pkg/", exchange -> respond(exchange, 404, "text/plain", ""));
|
||||
backend.createContext("/", exchange -> {
|
||||
uploadReceived.set(true);
|
||||
respond(exchange, 200, "text/plain", "");
|
||||
});
|
||||
when(service.containerBackedOverriddenVersionStatusesByRepository(any(), eq(DOMAIN), any(), eq(REPOSITORY),
|
||||
eq("pypi"))).thenReturn(Map.of("my-pkg", Map.of("1.0.0", "Disposed")));
|
||||
doThrow(new AwsException("ConflictException", "Package version '1.0.0' of package 'my-pkg' is Disposed "
|
||||
+ "and cannot be republished.", 409))
|
||||
.when(service).requireContainerBackedVersionNotArchivedOrDisposed(any(), eq(DOMAIN), any(),
|
||||
eq(REPOSITORY), eq("pypi"), isNull(), eq("my-pkg"), eq("1.0.0"));
|
||||
byte[] body = multipartWithFile("boundary123", "my-pkg", "my_pkg-1.0.0.tar.gz", "new content");
|
||||
|
||||
Response response = controller.upload(
|
||||
headers("Bearer good", "multipart/form-data; boundary=boundary123"), DOMAIN, REPOSITORY, body);
|
||||
|
||||
assertEquals(409, response.getStatus());
|
||||
assertEquals(false, uploadReceived.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Greptile's follow-up review of this PR: the form's own {@code name} field is no more
|
||||
* trustworthy than its missing {@code version} field, since pypiserver indexes a real upload
|
||||
* by the filename, never the form. {@code other-pkg}'s own overrides (there are none) must not
|
||||
* be the only ones checked: the filename actually names {@code my-pkg} version {@code 1.0.0},
|
||||
* which is Disposed, so the guard must still fire even though the form's {@code name} claims
|
||||
* an unrelated package.
|
||||
*/
|
||||
@Test
|
||||
void uploadWithNoVersionFieldStillRejectsAFilenameNamingADifferentArchivedOrDisposedPackage() {
|
||||
AtomicBoolean uploadReceived = new AtomicBoolean();
|
||||
backend.createContext("/simple/other-pkg/", exchange -> respond(exchange, 404, "text/plain", ""));
|
||||
backend.createContext("/", exchange -> {
|
||||
uploadReceived.set(true);
|
||||
respond(exchange, 200, "text/plain", "");
|
||||
});
|
||||
when(service.containerBackedOverriddenVersionStatusesByRepository(any(), eq(DOMAIN), any(), eq(REPOSITORY),
|
||||
eq("pypi"))).thenReturn(Map.of("my-pkg", Map.of("1.0.0", "Disposed")));
|
||||
doThrow(new AwsException("ConflictException", "Package version '1.0.0' of package 'my-pkg' is Disposed "
|
||||
+ "and cannot be republished.", 409))
|
||||
.when(service).requireContainerBackedVersionNotArchivedOrDisposed(any(), eq(DOMAIN), any(),
|
||||
eq(REPOSITORY), eq("pypi"), isNull(), eq("my-pkg"), eq("1.0.0"));
|
||||
byte[] body = multipartWithFile("boundary123", "other-pkg", "my_pkg-1.0.0.tar.gz", "new content");
|
||||
|
||||
Response response = controller.upload(
|
||||
headers("Bearer good", "multipart/form-data; boundary=boundary123"), DOMAIN, REPOSITORY, body);
|
||||
|
||||
assertEquals(409, response.getStatus());
|
||||
assertEquals(false, uploadReceived.get());
|
||||
}
|
||||
|
||||
/** A missing version field, same as the readme capture right below it, has no coordinate to clear. */
|
||||
@Test
|
||||
void uploadWithNoVersionFieldNeverClearsAnyStatusOverride() {
|
||||
|
||||
+23
@@ -3967,6 +3967,29 @@ class CodeArtifactServiceTest {
|
||||
verify(reposiliteClient, never()).fetchPackageVersionAsset(any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void containerBackedOverriddenVersionStatusesByRepositoryReturnsEveryOverriddenPackageInOneFormat() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
String repoId = created.getSidecarContainerIds().get("pypi");
|
||||
when(pypiserverClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg")))
|
||||
.thenReturn(List.of(
|
||||
new RepositorySidecarManager.PackageVersionTimestamp("1.0.0", Instant.ofEpochSecond(1000))));
|
||||
when(pypiserverClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("other-pkg")))
|
||||
.thenReturn(List.of(
|
||||
new RepositorySidecarManager.PackageVersionTimestamp("2.0.0", Instant.ofEpochSecond(2000))));
|
||||
|
||||
service.updatePackageVersionsStatus(REGION, "dom", null, "repo", "pypi", null, "my-pkg", List.of("1.0.0"),
|
||||
null, null, "Archived");
|
||||
service.updatePackageVersionsStatus(REGION, "dom", null, "repo", "pypi", null, "other-pkg", List.of("2.0.0"),
|
||||
null, null, "Unlisted");
|
||||
|
||||
assertEquals(Map.of("my-pkg", Map.of("1.0.0", "Archived"), "other-pkg", Map.of("2.0.0", "Unlisted")),
|
||||
service.containerBackedOverriddenVersionStatusesByRepository(REGION, "dom", null, "repo", "pypi"));
|
||||
assertEquals(Map.of(),
|
||||
service.containerBackedOverriddenVersionStatusesByRepository(REGION, "dom", null, "repo", "npm"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void disposePackageVersionsDeletesEveryRealAssetAndKeepsListingTheVersionAsDisposed() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
|
||||
Reference in new issue
Block a user