This is a trick for deep copy of a hash. I don't see any vulnerability here, but we can use JSON.load(val.to_json), the important is the result is completely new hash independent of the original val, because we modify it later.