The vulnerability exists in the next/script component, specifically within the Script function in packages/next/src/client/script.tsx. The advisory states that beforeInteractive scripts with untrusted input are vulnerable due to improper escaping. By analyzing the commits between the vulnerable version 16.2.4 and the patched version 16.2.5, I identified the security patch in commit 66f6017f157ae19eb30522105c789999de2de7af. The patch explicitly shows that the dangerouslySetInnerHTML prop was being populated with data from JSON.stringify without any escaping. The fix introduces a call to htmlEscapeJsonString to sanitize the serialized properties before they are embedded in the inline script. This directly addresses the described XSS vulnerability. Therefore, the Script function is the vulnerable function, as it is responsible for this unsafe serialization.