Skip to content

Commit 1311662

Browse files
authored
feat: Only install npm packages that have been available more than a day (#24338)
Bumps the default from 0 to 1 to enable the supply-chain delay by default while keeping the window short enough that the same-day Vaadin upgrade pain is at least bounded. Users can still opt out by setting the option to 0.
1 parent e434344 commit 1311662

7 files changed

Lines changed: 40 additions & 29 deletions

File tree

flow-build-tools/src/main/java/com/vaadin/flow/server/frontend/Options.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ public class Options implements Serializable {
168168

169169
/**
170170
* Minimum age, in days, that an npm/pnpm/bun frontend package version must
171-
* have before it is allowed to be installed. Defaults to {@code 0}
172-
* (disabled); set to a positive value to enable as a mitigation against
173-
* malicious packages published to the registry.
171+
* have before it is allowed to be installed. Defaults to {@code 1} day as a
172+
* mitigation against malicious packages published to the registry; set to
173+
* {@code 0} to disable.
174174
*/
175-
private int minimumFrontendPackageAgeDays = 0;
175+
private int minimumFrontendPackageAgeDays = 1;
176176

177177
private ApplicationConfiguration applicationConfiguration;
178178

flow-build-tools/src/test/java/com/vaadin/flow/server/frontend/TaskRunNpmInstallTest.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -765,17 +765,29 @@ private void assumeNPMIsInUse() {
765765
}
766766

767767
@Test
768-
void minimumFrontendPackageAge_defaultIsDisabled_returnsEmpty() {
769-
// Default is 0 (disabled) — no flag must be added
770-
assertFalse(TaskRunNpmInstall.getMinimumFrontendPackageAgeArgument(
771-
new MockOptions(npmFolder)).isPresent());
772-
assertFalse(TaskRunNpmInstall
773-
.getMinimumFrontendPackageAgeArgument(
774-
new MockOptions(npmFolder).withEnablePnpm(true))
775-
.isPresent());
776-
assertFalse(TaskRunNpmInstall
768+
void minimumFrontendPackageAge_defaultIsOneDay_addsArgument() {
769+
// Default is 1 day → 1440 minutes for pnpm, 86400 seconds for bun,
770+
// and a --before=<iso-instant> argument for npm
771+
assertTrue(TaskRunNpmInstall
777772
.getMinimumFrontendPackageAgeArgument(
778-
new MockOptions(npmFolder).withEnableBun(true))
773+
new MockOptions(npmFolder))
774+
.orElseThrow().startsWith("--before="));
775+
assertEquals("--config.minimum-release-age=1440",
776+
TaskRunNpmInstall
777+
.getMinimumFrontendPackageAgeArgument(
778+
new MockOptions(npmFolder).withEnablePnpm(true))
779+
.orElseThrow());
780+
assertEquals("--minimum-release-age=86400",
781+
TaskRunNpmInstall
782+
.getMinimumFrontendPackageAgeArgument(
783+
new MockOptions(npmFolder).withEnableBun(true))
784+
.orElseThrow());
785+
}
786+
787+
@Test
788+
void minimumFrontendPackageAge_zeroDisablesCheck_returnsEmpty() {
789+
assertFalse(TaskRunNpmInstall.getMinimumFrontendPackageAgeArgument(
790+
new MockOptions(npmFolder).withMinimumFrontendPackageAgeDays(0))
779791
.isPresent());
780792
}
781793

flow-plugins/flow-dev-bundle-plugin/src/main/java/com/vaadin/flow/plugin/maven/BuildDevBundleMojo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ public class BuildDevBundleMojo extends AbstractMojo
206206
* Minimum age (in days) a frontend (npm) package version must have before
207207
* npm, pnpm or bun is allowed to install it. Mitigates supply-chain attacks
208208
* where a compromised version is briefly available on the registry.
209-
* Defaults to {@code 0} (disabled); set to a positive value to enable.
210-
* Requires pnpm &ge; 10.16.0 or bun &ge; 1.3.0 when those tools are used.
209+
* Defaults to {@code 1} day; set to {@code 0} to disable. Requires pnpm
210+
* &ge; 10.16.0 or bun &ge; 1.3.0 when those tools are used.
211211
*/
212212
@Parameter(property = "vaadin."
213-
+ InitParameters.MINIMUM_FRONTEND_PACKAGE_AGE_DAYS, defaultValue = "0")
213+
+ InitParameters.MINIMUM_FRONTEND_PACKAGE_AGE_DAYS, defaultValue = "1")
214214
private int minimumFrontendPackageAgeDays;
215215

216216
/**

flow-plugins/flow-gradle-plugin/src/main/kotlin/com/vaadin/gradle/VaadinFlowPluginExtension.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,8 @@ public abstract class VaadinFlowPluginExtension @Inject constructor(private val
347347
* Minimum age (in days) a frontend (npm) package version must have before
348348
* npm, pnpm or bun is allowed to install it. Mitigates supply-chain
349349
* attacks where a compromised version is briefly available on the
350-
* registry. Defaults to {@code 0} (disabled); set to a positive value to
351-
* enable. Requires pnpm >= 10.16.0 or bun >= 1.3.0 when those tools are
352-
* used.
350+
* registry. Defaults to {@code 1} day; set to {@code 0} to disable.
351+
* Requires pnpm >= 10.16.0 or bun >= 1.3.0 when those tools are used.
353352
*/
354353
public abstract val minimumFrontendPackageAgeDays: Property<Int>
355354

@@ -659,7 +658,7 @@ public class PluginEffectiveConfiguration(
659658
project.getStringProperty(
660659
"vaadin.${InitParameters.MINIMUM_FRONTEND_PACKAGE_AGE_DAYS}"
661660
).map(String::toInt)
662-
.orElse(extension.minimumFrontendPackageAgeDays.convention(0))
661+
.orElse(extension.minimumFrontendPackageAgeDays.convention(1))
663662

664663
public val npmExcludeWebComponents: Provider<Boolean> = extension
665664
.npmExcludeWebComponents.convention(false)

flow-plugins/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/BuildFrontendMojo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ public class BuildFrontendMojo extends FlowModeAbstractMojo
149149
* Minimum age (in days) a frontend (npm) package version must have before
150150
* npm, pnpm or bun is allowed to install it. Mitigates supply-chain attacks
151151
* where a compromised version is briefly available on the registry.
152-
* Defaults to {@code 0} (disabled); set to a positive value to enable.
153-
* Requires pnpm &ge; 10.16.0 or bun &ge; 1.3.0 when those tools are used.
152+
* Defaults to {@code 1} day; set to {@code 0} to disable. Requires pnpm
153+
* &ge; 10.16.0 or bun &ge; 1.3.0 when those tools are used.
154154
*/
155155
@Parameter(property = "vaadin."
156-
+ InitParameters.MINIMUM_FRONTEND_PACKAGE_AGE_DAYS, defaultValue = "0")
156+
+ InitParameters.MINIMUM_FRONTEND_PACKAGE_AGE_DAYS, defaultValue = "1")
157157
private int minimumFrontendPackageAgeDays;
158158

159159
@Override

flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/plugin/base/PluginAdapterBuild.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ boolean checkRuntimeDependency(String groupId, String artifactId,
129129

130130
/**
131131
* Minimum age (in days) a frontend package version must have before npm,
132-
* pnpm or bun is allowed to install it. Defaults to {@code 0} (disabled);
133-
* set to a positive value to enable as a mitigation against malicious
134-
* packages briefly published to the registry.
132+
* pnpm or bun is allowed to install it. Defaults to {@code 1} day as a
133+
* mitigation against malicious packages briefly published to the registry;
134+
* set to {@code 0} to disable.
135135
*
136136
* @return the minimum allowed age in days, or {@code 0} when disabled
137137
*/
138138
default int minimumFrontendPackageAgeDays() {
139-
return 0;
139+
return 1;
140140
}
141141
}

flow-server/src/main/java/com/vaadin/flow/server/InitParameters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public class InitParameters implements Serializable {
304304
/**
305305
* Configuration name for the minimum age (in days) a frontend (npm) package
306306
* version must have before npm, pnpm or bun is allowed to install it.
307-
* Defaults to {@code 0} (disabled); set to a positive value to enable.
307+
* Defaults to {@code 1} day; set to {@code 0} to disable.
308308
*/
309309
public static final String MINIMUM_FRONTEND_PACKAGE_AGE_DAYS = "npm.minimumFrontendPackageAgeDays";
310310

0 commit comments

Comments
 (0)