Skip to content

Remove the _clean_stash method from WWSafe.pm. - #1572

Open
drgrice1 wants to merge 1 commit into
openwebwork:developfrom
drgrice1:safe-remove-clean-stash
Open

drgrice1 wants to merge 1 commit into
openwebwork:developfrom
drgrice1:safe-remove-clean-stash

Conversation

@drgrice1

@drgrice1 drgrice1 commented Nov 2, 2026

Copy link
Copy Markdown
Member

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 #1564. Note that this completely negates #1565 as well. See my comments in #1564 (comment) about why this is "secure enough".

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>
@drgrice1

drgrice1 commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

I will leave this open a bit longer, but I think that #1564 and #1565 are the better way to go.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant