I was trying to run CGI apps using wasmer-wasi. You need to pass the client headers to the CGI app using environment variables, but some client headers contain equal signs (e.g sec-ch-ua: "Chromium";v="86", "\"Not\\A;Brand";v="99", "Google Chrome";v="86"), which are rejected by wasmer-wasi, but work fine using wasmtime_wasi.
Setting a environment variable to a value containing an equal sign (=) is rejected by WasiStateBuilder::build, even though only keys may not contain equal signs. The first equal sign seperates the key from the value. Any other equal signs should be treated as part of the value.
[dependencies]
wasmer-wasi = "1.0.0-alpha3"
fn main() {
wasmer_wasi::WasiState::new("hello").env("DUMMY", "X=1").finalize().expect("this should work");
}
thread 'main' panicked at 'this should work: EnvironmentVariableFormatError("found \'=\' in env var string \"DUMMY=X=1\" (key=value)")', src/main.rs:2:73
Removing the incorrect check for multiple equal signs:
diff --git a/lib/wasi/src/state/builder.rs b/lib/wasi/src/state/builder.rs
index f6694bb02..6d5118e69 100644
--- a/lib/wasi/src/state/builder.rs
+++ b/lib/wasi/src/state/builder.rs
@@ -329,22 +329,9 @@ impl WasiStateBuilder {
}
}
for env in self.envs.iter() {
- let mut eq_seen = false;
for b in env.iter() {
match *b {
- b'=' => {
- if eq_seen {
- return Err(WasiStateCreationError::EnvironmentVariableFormatError(
- format!(
- "found '=' in env var string \"{}\" (key=value)",
- std::str::from_utf8(env)
- .unwrap_or("Inner error: env var is invalid_utf8!")
- ),
- ));
- }
- eq_seen = true;
- }
- 0 => {
+ 0 => {
return Err(WasiStateCreationError::EnvironmentVariableFormatError(
format!(
"found nul byte in env var string \"{}\" (key=value)",
It might make sense to add a check for equal signs in the key in the function WasiStateBuilder::env, so that WasiStateBuilder::build can return an error in such cases.
fn main() {
for (name,value) in std::env::vars() {
println!("{} = {}", name, value);
}
}
Output using wasmtime:
$ wasmtime run --env DUMMY=X=1 sample.wasm
DUMMY = X=1
Output using wasmer:
$ wasmer sample.wasm --env DUMMY=X=1
Error: Env vars must be of the form <var_name>=<value>. Found DUMMY=X=1
Hello,
Thanks for the bug report. I believe this might be a constraint from the specification itself. It is true however that having an equal sign inside the value part kind of make sense. I would be personally willing to authorize this. Thoughts @MarkMcCaskey?
That makes sense for me, probably we should allow DUMMY=A=B, by splitting by the first = encountered.
@ensch #1762 should solve your issue. If you can try it out, that would be helpful :-).
Works for me. Of course, .env("KEY=BAD", "Value") is now allowed and prints the unexpected KEY = BAD=Value.
Discussion continues at #1762.