question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request to limit scope of functions in validator.js

See original GitHub issue

What’s the issue?

It seems that functions in validator.js are escaping into the global namespace.

How do we reproduce the issue?

  1. Navigate to an AMP page like this, with #development=1 appended to the URL.
  2. Open the browser’s console, and enter wp.
  3. Expected: wp is not defined
  4. Actual: wp is a function:
ƒ wp(a){rp.call(this);this.name=a;this.value=[];this.b=!1;this.o=34}

It looks like this script leaks functions into the global namespace:

https://cdn.ampproject.org/v0/validator.js

There are other functions leaked, like aa.

Maybe that script is intended for development only, as it seems that it’s not requested if #development=1 isn’t appended. But it would really help us with this issue on the AMP WordPress plugin:

https://github.com/Automattic/amp-wp/issues/843

We’re working on validating AMP in the WordPress editor.

What browsers are affected?

Chrome 63.0.3239.132

Which AMP version is affected?

1516337355291

Thanks a lot for your help 😄

/cc @amedina, @Gregable, @pbakaus

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Gregablecommented, Jan 25, 2018

I think we can get a fix out for this fairly quickly. @powdercloud has a prototype, but we need to get it through a release. Thanks for the report.

0reactions
kienstracommented, Feb 22, 2018

Thank You

Hi @powdercloud and @Gregable, Thanks a lot for fixing this. As you mentioned, validator.js is wrapped in a function, and functions like wp aren’t leaked.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to restrict the scope of a javascript function?
Run the code in an iframe hosted on a different Origin. This is the only way to guarantee that untrusted code is sandboxed...
Read more >
validate.js
Validate.js provides a declarative way of validating javascript objects. It is unit tested with 100% code coverage and can be considered fit for...
Read more >
Client-side form validation - Learn web development | MDN
Client-side form validation sometimes requires JavaScript if you want to customize styling and error messages, but it always requires you to think carefully ......
Read more >
Variable scope - Manual - PHP
There is no limit to the number of global variables that can be manipulated by a function. A second way to access variables...
Read more >
Spring Validation Example - Spring MVC Form Validator
When we accept user inputs in any web application, it becomes necessary to validate them. We can validate the user input at the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found