diff --git a/src/uboot_env.c b/src/uboot_env.c
index 16aa416da20f..1b35d898ee62 100644
--- a/src/uboot_env.c
+++ b/src/uboot_env.c
@@ -1011,6 +1011,15 @@ int libuboot_set_env(struct uboot_ctx *ctx, const char *varname, const char *val
 		if (!entryvarlist)
 			return -EPERM;
 	}
+
+	if (value && storages[ctx->format]->validate) {
+		int ret;
+
+		ret = storages[ctx->format]->validate(ctx, varname, value);
+		if (ret)
+			return ret;
+	}
+
 	return __libuboot_set_env(ctx, varname, value, entryvarlist);
 }
 
diff --git a/src/uboot_private.h b/src/uboot_private.h
index 9fd8c5f996c9..52c3fff21c42 100644
--- a/src/uboot_private.h
+++ b/src/uboot_private.h
@@ -212,6 +212,9 @@ struct env_storage {
 	int (*load)(struct uboot_ctx *ctx, const struct env_helpers *h);
 	/** write the variable list to the storage */
 	int (*store)(struct uboot_ctx *ctx, const struct env_helpers *h);
+	/** check a value before it is set, can be NULL */
+	int (*validate)(struct uboot_ctx *ctx, const char *varname,
+			const char *value);
 };
 
 #if defined(__FreeBSD__)
