You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constpug=require('pug');global.config={siteName: 'My Site'};consttestPug=`p Old Site Name: #{config.siteName}- config.siteName = 'Hacked Site'p New Site Name: #{config.siteName}`;constcompiled=pug.compile(testPug);console.log(compiled());
Output:
<p>Old Site Name: My Site</p><p>New Site Name: Hacked Site</p>
The config is now persistently modified:
console.log(config);
Ouput:
{ siteName: 'Hacked Site' }
Workaround
To prevent access to the global variables, you can also set them locally to "undefined".
Pug Version: 3.0.2
Node Version: 18.18.2
Steps to Reproduce:
Test Code:
Output:
The config is now persistently modified:
Ouput:
Workaround
To prevent access to the global variables, you can also set them locally to "undefined".
Solution
Adding a
"use strict";
to the compiled function might also prevent the access to global variables.The text was updated successfully, but these errors were encountered: