Repository navigation
Conversation
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
084d44d to
21a4142
Compare
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The `WWSafe.pm` module is based on version 2.47 of the upstream `Safe.pm` module, which includes a `_clean_stash` method that deletes the `DESTROY`, `AUTOLOAD`, and overload methods defined by compartment code after the compartment code is executed. This is intended to prevent that code from running outside of the safe compartment (for instance when an object is destroyed, since destruction happens outside the compartment), where it would run with the `main::` symbol table rather than the compartment's isolated one. However, this breaks macros that legitimately define such methods. For example, the `AUTOLOAD` method of `context::Extensions::Super` in `contextExtensions.pl` (used by `contextFraction.pl`, `contextUnits.pl`, and `contextSignificantFigures.pl`) is deleted, which breaks any context that extends another context, such as using the Units context together with the SignificantFigures context. The other improvements from the 2.47 update (the `reval`/`rdo` reentrancy handling and the wrapping of code references returned from the compartment) are retained. This is an alternative, perhaps slightly less secure but yet secure enough, approach to fixing the issue created with the `contextExtensions.pl` macro by the updated `WWSafe.pm` module to openwebwork#1564. Note that this completely negates openwebwork#1565 as well. See my comments in openwebwork#1564 (comment) about why this is "secure enough". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The `WWSafe.pm` module is based on version 2.47 of the upstream `Safe.pm` module, which includes a `_clean_stash` method that deletes the `DESTROY`, `AUTOLOAD`, and overload methods defined by compartment code after the compartment code is executed. This is intended to prevent that code from running outside of the safe compartment (for instance when an object is destroyed, since destruction happens outside the compartment), where it would run with the `main::` symbol table rather than the compartment's isolated one. However, this breaks macros that define such methods. For example, the `AUTOLOAD` method of `context::Extensions::Super` in `contextExtensions.pl` (used by `contextFraction.pl`, `contextUnits.pl`, and `contextSignificantFigures.pl`) is deleted, which breaks any context that extends another context, such as using the Units context together with the SignificantFigures context. The other improvements from the 2.47 update (the `reval`/`rdo` reentrancy handling and the wrapping of code references returned from the compartment) are retained. This is an alternative, perhaps slightly less secure but yet secure enough, approach to fixing the issue created with the `contextExtensions.pl` macro by the updated `WWSafe.pm` module to openwebwork#1564. Note that this completely negates openwebwork#1565 as well. See my comments in openwebwork#1564 (comment) about why this is "secure enough". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Anything this needs to test? I've run things that load pg problems and everything still seems to work. perhaps, we should merge and will continue to test over the next few months? |
|
Do not rush to merge this. There is a pending decision that needs to be made. Basically, this pull request goes with #1564, and this pull request and #1564 are alternates to #1572. This pull request extends stripping of the |
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@drgrice1 Let's discuss this today unless you did last week. |
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
21a4142 to
da7a544
Compare
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
da7a544 to
2456e2a
Compare
somiaj
left a comment
There was a problem hiding this comment.
Tested a bunch of problems. Everything works. I trust that this fixes the possible security issues with the hooks.
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ent. The `_clean_stash` method deletes the `DESTROY`, `AUTOLOAD`, and overload methods defined by compartment code after it runs, so that the code is not executed outside the safe compartment (for example when an object is destroyed), where it would run with the `main::` symbol table and could reach privileged subroutines by name. It skipped the shared packages that are aliased into the compartment via `share_from` (such as the MathObjects `Value::` tree), since deleting a hook from one of those would corrupt the package. But that left a problem or macro free to define a hook under a shared namespace (for example a `DESTROY` method in a new `Value::Evil` package, or by overwriting an existing overload such as `Complex1::(+` in place), and that hook survived the cleanup. To close this, `snapshot_hooks` now records the hooks that in shared packages, once the compartment is fully set up but before any problem or macro code runs. `_clean_stash` then uses that cache to restore any shared hook that problem or macro code overwrote, and strip all hooks that problem or macro code added. So hooks in packages defined inside the safe compartment are stripped as before, but also hooks that are defined inside the safe compartment using basename of the namespace of a shared package are stripped (so `Value::Evil` is stripped, but not `Value::Real`). To keep this cheap, overwritten hooks are found by walking the recorded baseline hook list, and added hooks are looked for only in the shared packages whose key count changed since the baseline, so the (static) shared packages that problem code did not touch are not re-walked. The baseline is recorded at the end of the compartment setup (in the BEGIN block when rendering in a Mojolicious app, and at the end of `unrestricted_load` otherwise). This also updates some out of date comments that described the cached safe compartment as being for the "standalone renderer". In general it is used whenever rendering in a Mojolicious app, which now includes webwork2. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2456e2a to
e4ac8ed
Compare
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This uses the same shared-package defense from the pg pull request openwebwork/pg#1565. The `snapshot_hooks` method can be called to record the hooks in the shared packages once the compartment is fully set up but before the user provided code runs, and `_clean_stash` then uses that to restore any shared hook the user supplied code overwrites in place and strip all hooks the user provided code adds (so a hook in a new `Mojo::Exception::Evil` package is stripped, but `Mojo::Exception`'s overloads are left alone). `snapshot_hooks` is called from the `AchievementNotification` task, which is the only consumer that shares whole package stashes into a compartment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The
_clean_stashmethod deletes theDESTROY,AUTOLOAD, and overload methods defined by compartment code after it runs, so that the code is not executed outside the safe compartment (for example when an object is destroyed), where it would run with themain::symbol table and could reach privileged subroutines by name. It skipped the shared packages that are aliased into the compartment viashare_from(such as the MathObjectsValue::tree), since deleting a hook from one of those would corrupt the package. But that left a problem or macro free to define a hook under a shared namespace (for example aDESTROYmethod in a newValue::Evilpackage, or by overwriting an existing overload such asComplex1::(+in place), and that hook survived the cleanup.To close this,
snapshot_hooksnow records the hooks that in shared packages, once the compartment is fully set up but before any problem or macro code runs._clean_stashthen uses that cache to restore any shared hook that problem or macro code overwrote, and strip all hooks that problem or macro code added. So hooks in packages defined inside the safe compartment are stripped as before, but also hooks that are defined inside the safe compartment using basename of the namespace of a shared package are stripped (soValue::Evilis stripped, but notValue::Real).To keep this cheap, overwritten hooks are found by walking the recorded baseline hook list, and added hooks are looked for only in the shared packages whose key count changed since the baseline, so the (static) shared packages that problem code did not touch are not re-walked. The baseline is recorded at the end of the compartment setup (in the BEGIN block when rendering in a Mojolicious app, and at the end of
unrestricted_loadotherwise).This also updates some out of date comments that described the cached safe compartment as being for the "standalone renderer". In general it is used whenever rendering in a Mojolicious app, which now includes webwork2.