Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add overrideTaming: 'severe' #730

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions packages/browserify/test/globals.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
const test = require('ava')
const {
runScenario,
createBrowserifyScenarioFromScaffold,
} = require('./util')
const {
runAndTestScenario,
} = require('lavamoat-core/test/util.js')
const { runScenario, createBrowserifyScenarioFromScaffold } = require('./util')
const { runAndTestScenario } = require('lavamoat-core/test/util.js')

// TODO: this should be resolving to a browserify dependency
// eslint-disable-next-line ava/no-skip-test
Expand All @@ -27,3 +22,14 @@ test('globals - process is properly injected', async (t) => {
})
await runAndTestScenario(t, scenario, runScenario)
})

test('globals - basic override mistake taming is on', async (t) => {
const scenario = createBrowserifyScenarioFromScaffold({
defineOne: () => {
Object.assign({}, { constructor: () => 1 })
module.exports = 1
},
expectedResult: 1,
})
await runAndTestScenario(t, scenario, runScenario)
})
2 changes: 2 additions & 0 deletions packages/core/src/kernelTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
errorTaming: 'unsafe',
// shows the full call stack
stackFiltering: 'verbose',
// prevents most common override mistake cases from tripping up users
overrideTaming: 'severe',
}

lockdown(lockdownOptions)
Expand Down
38 changes: 23 additions & 15 deletions packages/node/test/globals.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ const { createScenarioFromScaffold } = require('lavamoat-core/test/util')
test('globals - has only the expected global circular refs', async (t) => {
const scenario = createScenarioFromScaffold({
defineOne: () => {
const circularKeys = Reflect.ownKeys(globalThis)
.filter(key => {
const value = globalThis[key]
return value === globalThis
})
const circularKeys = Reflect.ownKeys(globalThis).filter((key) => {
const value = globalThis[key]
return value === globalThis
})
module.exports = circularKeys
},
expectedResult: [
'global',
'globalThis',
],
expectedResult: ['global', 'globalThis'],
})
const testResult = await runScenario({ scenario })
t.is(Array.isArray(testResult), true)
Expand All @@ -29,14 +25,14 @@ test('globalRef - globalRef - check default containment', async (t) => {
defineOne: () => {
const testResults = {}
try {
testResults.objCheckThis = this.Object === Object
} catch (_) { }
testResults.objCheckThis = this.Object === Object
} catch (_) {}
try {
testResults.objCheckGlobal = global.Object === Object
} catch (_) { }
testResults.objCheckGlobal = global.Object === Object
} catch (_) {}
try {
testResults.thisIsExports = exports === this
} catch (_) { }
testResults.thisIsExports = exports === this
} catch (_) {}
module.exports = testResults
},
expectedResult: {
Expand All @@ -48,3 +44,15 @@ test('globalRef - globalRef - check default containment', async (t) => {
const testResult = await runScenario({ scenario })
scenario.checkResult(t, testResult, scenario)
})

test('globals - basic override mistake taming is on', async (t) => {
const scenario = createScenarioFromScaffold({
defineOne: () => {
Object.assign({}, { constructor: () => 1 })
module.exports = 1
},
expectedResult: 1,
})
const testResult = await runScenario({ scenario })
scenario.checkResult(t, testResult, scenario)
})