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

refactor: allow resolution of variables in the proto chain #578

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

caridy
Copy link

@caridy caridy commented Nov 7, 2021

resolveVariableReference enforces variables names to be own properties. This seems to be very restrictive, and instead, Reflect.has() or in operator is probably better. In our case, the args structure provided to messages might be optimized in various ways (very likely be immutable structures) that does not necessary have a flatten structure, and instead it might rely on the __proto__ chain.

Perf Considerations

I believe this change will not necessary introduce a significant chante in terms of performance. Yes, missing variable names lookups will take one more step (most likely a look up on Object.prototype which is probably optimized by engines already), but that should not move the needle IMO.

Security Implications

The interpolation is already very secure (by doing the escaping), with this change, poisoning of the Object.prototype is possible, but again, you can only attack message if the consumer is not providing the variable name, in which case Object.prototype lookup will occur. There are other different ways to do a similar attack, including patching Object.prototype.hasOwnProperty on itself :), so I will consider this to not be an issue.

TODO

  • update tests

@@ -156,14 +156,14 @@ function resolveVariableReference(
let arg: FluentVariable;
if (scope.params) {
// We're inside a TermReference. It's OK to reference undefined parameters.
if (Object.prototype.hasOwnProperty.call(scope.params, name)) {
if (Reflect.has(scope.params, name)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reflect.has is not available in IE11. This project doesn't provide details about the level of support that it is offering for legacy browsers, judging by the code, I don't see any usage of Reflect. We can replace this with name in scope.params which is equivalent and does work in legacy systems as well.

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