Skip to content

Commit

Permalink
- Resolved an error attempting to decode a prohibited impersonation t…
Browse files Browse the repository at this point in the history
…oken.
  • Loading branch information
shauncummings committed Nov 3, 2023
1 parent 75ad4d9 commit 23e4981
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions Rock/Model/Core/PersonToken/PersonTokenService.cs
Expand Up @@ -33,17 +33,30 @@ public partial class PersonTokenService
/// <returns></returns>
public PersonToken GetByImpersonationToken( string impersonationToken )
{
if ( impersonationToken == "TokenProhibited" )
{
// This indicates that there was an attempt to generate a token for a person whose security settings do not permit it. Exit here, before attempting to decrypt the token.
return null;
}

// the impersonationToken should normally be a UrlEncoded string, but it is possible that the caller already UrlDecoded it, so first try without UrlDecoding it
var decryptedToken = Rock.Security.Encryption.DecryptString( impersonationToken );

if ( decryptedToken == null )
{
// do a Replace('!', '%') on the token before UrlDecoding because we did a Replace('%', '!') after we UrlEncoded it (to make it embeddable in HTML and cross browser compatible)
string urlDecodedKey = System.Web.HttpUtility.UrlDecode( impersonationToken.Replace( '!', '%' ) );
decryptedToken = Rock.Security.Encryption.DecryptString( urlDecodedKey );
string urlDecodedToken = System.Web.HttpUtility.UrlDecode( impersonationToken.Replace( '!', '%' ) );

if ( urlDecodedToken == "TokenProhibited" )
{
// This indicates that there was an attempt to generate a token for a person whose security settings do not permit it. Exit here, before attempting to decrypt the token.
return null;
}

decryptedToken = Rock.Security.Encryption.DecryptString( urlDecodedToken );
}

var personToken = this.Queryable().Include(pt => pt.PersonAlias).FirstOrDefault( a => a.Token == decryptedToken );
var personToken = this.Queryable().Include( pt => pt.PersonAlias ).FirstOrDefault( a => a.Token == decryptedToken );
if ( personToken == null )
{
bool tokenUseLegacyFallback = GlobalAttributesCache.Get().GetValue( "core.PersonTokenUseLegacyFallback" ).AsBoolean();
Expand Down

0 comments on commit 23e4981

Please sign in to comment.