$f,g,h: \mathbf R\to\mathbf R$. $h$ is differentiable while $f$ and $g$ are integrable. $B_t$ is a Brownian motion. We know that $$\mathbf E\bigg[h\Big(\int_0^1 f(t)dB_t\Big)\int_0^1g(t)dB_t\bigg]=\mathbf E\bigg[h'\Big(\int_0^1 f(t)dB_t\Big)\int_0^1f(t)g(t)dt\bigg].$$ This is obtained by viewing $z:=\int_0^1 g(t)\,dB_t$ as a Gaussian random variable with mean $0$ and variance $\int_0^1 g(t)^2\,dt$, then $\int_0^1 f(t)dB_t$ has the same distribution as $z\sqrt\frac{\int_0^1 f^2}{\int_0^1 g^2}$, then finishing by integration by parts on the normal distribution.
Is the following generalization true?
For integrable $g_1:\mathbf R\to\mathbf R$, $$\mathbf E\bigg[h\Big(\int_0^1 f(t)dB_t\Big)\int_0^1g(t)\int_0^tg_1(t_1)\,dB_{t_1}\,dB_t\bigg]=\mathbf E\bigg[h'\Big(\int_0^1 f(t)dB_t\Big)\int_0^1f(t)g(t)\int_0^tg_1(t_1)\,dB_{t_1}dt\bigg]$$ Of course, if the right-hand side holds, we can apply the first identity again.
Presumably this has to do with Malliavin calculus, but I have not found a direct reference to a proof or counterexample.
Writing $M_t = \int_0^t g_1(t_1)dB_{t_1}$, $t\in[0,1]$, then $M$ is in the domain of Skorokhod divergence $\delta$ [see https://en.wikipedia.org/wiki/Skorokhod_integral ]. Write $F = \int_0^1 f(t) dB_t$, which is in the domain of Malliavin derivative $D$. Note $$\int_0^1 g(t) M_t dB_t = \delta\big( g M\big) $$ because $t\in[0,1]\to g_tM_t$ is adapted, so that the LHS can be expressed as $$\mathbf{E}\Big[ h(F) \delta(gM) \Big] $$ which is equal to, due to the duality relation between $D$ and $\delta$, $$ \mathbf{E}\Big[ \big\langle Dh(F) ,gM\big\rangle_{L^2([0,1],dx)} \Big] = \mathbf{E}\Big[h'(F) \big\langle DF ,gM\big\rangle_{L^2([0,1],dx)} \Big] = \mathbf{E}\Big[h'(F) \big\langle f ,gM\big\rangle_{L^2([0,1],dx)} \Big]$$ which is equal to the RHS.