Skip to content

Commit 94f32e3

Browse files
nicolstfcomte
authored andcommitted
Fix arbitrary Helm list parameter injection
1 parent f5186ec commit 94f32e3

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

helm-wrapper/src/main/java/io/github/inseefrlab/helmwrapper/service/HelmInstallService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class HelmInstallService {
3131
private final Pattern semverPattern =
3232
Pattern.compile(
3333
"^(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-]+)*))?$");
34+
private final Pattern rfc1123Pattern = Pattern.compile("^[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$");
3435

3536
private final HelmReleaseInfoParser helmReleaseInfoParser = new HelmReleaseInfoParser();
3637
private static final String VALUES_INFO_TYPE = "values";
@@ -299,6 +300,13 @@ private String buildEnvVar(Map<String, String> env) {
299300
*/
300301
public HelmLs getAppById(HelmConfiguration configuration, String appId, String namespace)
301302
throws MultipleServiceFound {
303+
if (appId.length() > 53 || !rfc1123Pattern.matcher(appId).matches()) {
304+
throw new IllegalArgumentException(
305+
"Invalid app id "
306+
+ appId
307+
+ ". Must be 53 or fewer characters and be a valid RFC 1123 string.");
308+
}
309+
302310
StringBuilder command = new StringBuilder("helm list --filter ");
303311
safeConcat(command, appId);
304312
command.append(" -n ");

0 commit comments

Comments
 (0)