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

Purge expired auth cookies #5001

Merged
merged 2 commits into from
Feb 16, 2022
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
1 change: 1 addition & 0 deletions DNN Platform/Library/DotNetNuke.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@
<Compile Include="Security\Cookies\AuthCookieController.cs" />
<Compile Include="Security\Cookies\IAuthCookieController.cs" />
<Compile Include="Security\Cookies\PersistedAuthCookie.cs" />
<Compile Include="Security\Cookies\PurgeAuthCookiesTask.cs" />
<Compile Include="Security\FIPSCompliant.cs" />
<Compile Include="Security\Membership\AspNetMembershipProvider.cs" />
<Compile Include="Security\Permissions\CorePermissionProvider.cs" />
Expand Down
43 changes: 43 additions & 0 deletions DNN Platform/Library/Security/Cookies/PurgeAuthCookiesTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Security.Cookies
{
using System;

using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Scheduling;

/// <summary>
/// Scheduled task to remove old cookies.
/// </summary>
public class PurgeAuthCookiesTask : SchedulerClient
{
/// <summary>
/// Initializes a new instance of the <see cref="PurgeAuthCookiesTask"/> class.
/// </summary>
/// <param name="objScheduleHistoryItem">Object that will get added to the database as a record of this run.</param>
public PurgeAuthCookiesTask(ScheduleHistoryItem objScheduleHistoryItem)
{
this.ScheduleHistoryItem = objScheduleHistoryItem;
}

/// <inheritdoc/>
public override void DoWork()
{
try
{
AuthCookieController.Instance.DeleteExpired(DateTime.UtcNow);
this.ScheduleHistoryItem.Succeeded = true;
this.ScheduleHistoryItem.AddLogNote("Purging auth cookies completed");
}
catch (Exception exc)
{
this.ScheduleHistoryItem.Succeeded = false;
this.ScheduleHistoryItem.AddLogNote(string.Format("Purging auth cookies task failed: {0}.", exc.ToString()));
this.Errored(ref exc);
Exceptions.LogException(exc);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,35 @@ WHERE SettingName = 'SSLSetup'
AND SettingValue = 'True'
GO


/* Add scheduled task to delete expired auth cookies */
/************************************************************/

IF NOT EXISTS(SELECT ScheduleID FROM {databaseOwner}[{objectQualifier}Schedule] WHERE TypeFullName = 'DotNetNuke.Security.Cookies.PurgeAuthCookiesTask, DOTNETNUKE')
BEGIN
INSERT INTO {databaseOwner}[{objectQualifier}Schedule] ([TypeFullName], [TimeLapse], [TimeLapseMeasurement], [RetryTimeLapse], [RetryTimeLapseMeasurement], [RetainHistoryNum], [AttachToEvent], [CatchUpEnabled], [Enabled], [ObjectDependencies], [Servers], [CreatedByUserID], [CreatedOnDate], [LastModifiedByUserID], [LastModifiedOnDate], [FriendlyName])
VALUES ('DotNetNuke.Security.Cookies.PurgeAuthCookiesTask, DOTNETNUKE', 1, 'h', 30, 'm', 10, '', 0, 1, '', NULL, NULL, GETDATE(), NULL, GETDATE(), N'Purge Expired Authentication Cookies')
END
GO

IF object_id(N'{databaseOwner}[{objectQualifier}AuthCookies_DeleteOld]', 'P') IS NOT NULL
DROP PROCEDURE {databaseOwner}[{objectQualifier}AuthCookies_DeleteOld]
GO

/* Ensure that the AuthCookies doesn't time out */
/************************************************************/

CREATE PROCEDURE {databaseOwner}[{objectQualifier}AuthCookies_DeleteOld]
@CutoffDate datetime -- in UTC
AS
BEGIN
DELETE TOP(10000) FROM {databaseOwner}[{objectQualifier}AuthCookies]
WHERE ExpiresOn < @CutoffDate
END
GO



/************************************************************/
/***** SqlDataProvider *****/
/************************************************************/