Files
Janka UrygaandGitHub 660026d50b fix: this in edge sandbox setTimeout/setInterval (#94754)
Our attempts at setting the correct `this` in our
`setTimeout`/`setInterval` polyfills were slightly incorrect, because
they used the wrong global object.

(Thanks to [cyberjoker](https://hackerone.com/cyberjoker) for
discovering this)
2026-06-12 21:28:39 +00:00

25 lines
817 B
TypeScript

export const runtime = 'edge'
export async function GET() {
const result = await new Promise<string>((resolve) => {
setTimeout(function (this: typeof globalThis) {
try {
// The `this` available here should be the edge sandbox global object,
// not the one from node. If we get the node one, we can access require
// and thus modules that are not allowed in the edge runtime, like 'fs'.
const outerGlobalThis = this
const fs = outerGlobalThis.process.mainModule!.require(
'fs'
) as typeof import('fs')
fs.writeFileSync('hello.txt', 'sandbox? what sandbox?')
resolve('escape successful')
} catch (error) {
resolve('escape failed:\n' + (error as Error).toString())
}
})
})
return new Response(result)
}