Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:gocodebox/lifterlms into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasplevy committed Sep 14, 2022
2 parents 2ba3cfd + 0d0c95d commit c4068de
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changelogs/achievements-hash-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
significance: patch
type: security
links:
- gocodebox/private-issues#61
entry: Fixed a data sanitization issue related to achievement permalinks.
29 changes: 21 additions & 8 deletions assets/js/app/llms-achievements.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package LifterLMS/Scripts
*
* @since 3.14.0
* @version 4.5.1
* @version [version]
*/

LLMS.Achievements = {
Expand All @@ -15,7 +15,7 @@ LLMS.Achievements = {
* @since 3.14.0
* @since 4.5.1 Fix conditional loading check.
*
* @return void
* @return {void}
*/
init: function() {

Expand All @@ -36,7 +36,7 @@ LLMS.Achievements = {
*
* @since 3.14.0
*
* @return void
* @return {void}
*/
bind: function() {

Expand Down Expand Up @@ -70,7 +70,7 @@ LLMS.Achievements = {
* @since 3.14.0
*
* @param obj $el The jQuery selector for the modal card.
* @return void
* @return {void}
*/
create_modal: function( $el ) {

Expand Down Expand Up @@ -111,16 +111,29 @@ LLMS.Achievements = {
* On page load, opens a modal if the URL contains an achievement in the location hash
*
* @since 3.14.0
* @since [version] Sanitize achievement IDs before using window.location.hash to trigger the modal open.
*
* @return void
* @return {void}
*/
maybe_open: function() {

var hash = window.location.hash;
if ( hash && -1 !== hash.indexOf( 'achievement-' ) ) {
$( 'a[href="' + hash + '"]' ).first().trigger( 'click' );
let hash = window.location.hash.split( '-' );
if ( 2 !== hash.length ) {
return;
}

hash[1] = parseInt( hash[1] );
if ( '#achievement-' !== hash[0] || ! Number.isInteger( hash[1] ) ) {
return;
}

const a = document.querySelector( `a[href="${ hash.join( '-' ) }"]` )
if ( ! a ) {
return;
}

a.click();

}

};

0 comments on commit c4068de

Please sign in to comment.