samualtnorman / hackmud-script-manager

Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.
https://www.npmjs.com/package/hackmud-script-manager
MIT License
11 stars 5 forks source link

Make compiled subscript invocation use the secLevel they have in the source #201

Closed VincentGuinaudeau closed 6 months ago

VincentGuinaudeau commented 6 months ago

Instead of using the ambient secLevel, this PR makes it so that each call to a subscript keeps the secLevel specified in the source.

This makes depending on other scripts more secure, since we can specify a higher secLevel than our script for any particular subscript call, and hackmud will enforce this secLevel at runtime.

When multiple calls are merged into one, this PR choose the highest secLevel, for security. This might cause issues if different secLevel are used to call the same script, with a genuine use case if the subscript is expect to change secLevel and you want your script to react accordingly, but this seems far fetched to me.

I tested this PR on my own scripts, with subscript call in the main function, in the global scope, in other functions in the same file, and in other files imported via the esm syntax.

samualtnorman commented 6 months ago

this is great work! thank you.

VincentGuinaudeau commented 6 months ago

Thanks for the review, I made all the requested changes.

Also, I noticed that I broke the quine cheating, because it too use the $SUBSCRIPT$ intermediate representation. So I modified every place where it is injected to add the seclevel.

samualtnorman commented 6 months ago

Also, I noticed that I broke the quine cheating, because it too use the $SUBSCRIPT$ intermediate representation. So I modified every place where it is injected to add the seclevel.

Woops. That's my fault for poor design. As this project grows in complexity, we will need to switch from using hardcoded names.

samualtnorman commented 6 months ago

ty