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

Widget: Don't let widget name affect $.ui prototype & constructor #2310

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/unit/widget/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,28 @@ QUnit.test( "error handling", function( assert ) {
$.error = error;
} );

QUnit.test( "Prototype pollution", function( assert ) {
assert.expect( 3 );

var elem = $( "<div>" );

$.widget( "ui.testWidget", {} );

elem.testWidget();

try {
$.widget( "ui.__proto__", {} );
} catch ( _e ) {}
try {
$.widget( "ui.constructor", {} );
} catch ( _e ) {}

assert.strictEqual( Object.getPrototypeOf( $.ui ), Object.prototype,
"$.ui constructor not modified" );
assert.ok( $.ui instanceof Object, "$.ui is an Object instance" );
assert.notOk( $.ui instanceof Function, "$.ui is not a Function instance" );
} );

QUnit.test( "merge multiple option arguments", function( assert ) {
assert.expect( 1 );
$.widget( "ui.testWidget", {
Expand Down
3 changes: 3 additions & 0 deletions ui/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ $.widget = function( name, base, prototype ) {

var namespace = name.split( "." )[ 0 ];
name = name.split( "." )[ 1 ];
if ( name === "__proto__" || name === "constructor" ) {
return $.error( "Invalid widget name: " + name );
}
var fullName = namespace + "-" + name;

if ( !prototype ) {
Expand Down
Loading