Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix command injection vulnerability in HelmInstallService #539

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class HelmInstallService {
private static final Logger LOGGER = LoggerFactory.getLogger(HelmInstallService.class);
private final Pattern helmNamePattern =
Pattern.compile("^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$");
private final Pattern semverPattern =
Pattern.compile(
"^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");

private final HelmReleaseInfoParser helmReleaseInfoParser = new HelmReleaseInfoParser();
private static final String VALUES_INFO_TYPE = "values";
Expand Down Expand Up @@ -173,6 +176,10 @@ public HelmInstaller installChart(
command.append("-n ");
safeConcat(command, namespace);
if (StringUtils.isNotBlank(version)) {
if (!semverPattern.matcher(version).matches()) {
throw new IllegalArgumentException(
"Invalid release version " + version + ", must be a SemVer 2 string");
}
command.append(" --version ");
safeConcat(command, version);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ private Collection<Object> publishApps(

Pkg pkg =
catalog.getCatalog()
.getPackageByName(requestDTO.getPackageName())
.getPackageByNameAndVersion(
requestDTO.getPackageName(), requestDTO.getPackageVersion())
.orElseThrow(NotFoundException::new);

Map<String, Object> fusion = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Collection<Object> installApp(
catalogId + "/" + pkg.getName(),
namespaceId,
requestDTO.getName(),
requestDTO.getPackageVersion(),
pkg.getVersion(),
requestDTO.isDryRun(),
values,
null,
Expand Down
Loading