We are concerned with the optimal control of a nonlinear stochastic heat equation on a bounded real interval with Neumann boundary conditions. The specificity here is that both the control and the noise act on the boundary. We start by reformulating the state equation as an infinite dimensional stochastic evolution equation. The first main result of the paper is the proof of existence and uniqueness of a mild solution for the corresponding Hamilton-Jacobi-Bellman (HJB) equation. The C 1 regularity of such a solution is then used to construct the optimal feedback for the control problem. In order to overcome the difficulties arising from the degeneracy of the second order operator and from the presence of unbounded terms we study the HJB equation by introducing a suitable forward-backward system of stochastic differential equations as in the appraoch proposed in [Fuhrman and Tessitore, Ann. Probab.30 (2002) 1397-1465; Pardoux and Peng, Lect. Notes Control Inf. Sci.176 (1992) 200-217] for finite dimensional and infinite dimensional semilinear parabolic equations respectively.