Skip to content

Commit

Permalink
Merge pull request #533 from msalemcode/main
Browse files Browse the repository at this point in the history
Mitigated CodeQL logging security Alerts
  • Loading branch information
msalemcode authored Aug 5, 2023
2 parents de7bc3d + b697567 commit f3fcf7c
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 157 deletions.
11 changes: 6 additions & 5 deletions src/AdminSite/Controllers/ApplicationConfigController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Web;
using Marketplace.SaaS.Accelerator.DataAccess.Contracts;
using Marketplace.SaaS.Accelerator.DataAccess.Entities;
using Marketplace.SaaS.Accelerator.Services.Services;
Expand All @@ -21,8 +22,7 @@ namespace Marketplace.SaaS.Accelerator.AdminSite.Controllers;
[ServiceFilter(typeof(RequestLoggerActionFilter))]
public class ApplicationConfigController : BaseController
{
private readonly ILogger<ApplicationConfigController> logger;

private readonly SaaSClientLogger<ApplicationConfigController> logger;
private readonly ApplicationConfigService appConfigService;

/// <summary>
Expand All @@ -31,9 +31,8 @@ public class ApplicationConfigController : BaseController
private readonly IEmailTemplateRepository emailTemplateRepository;

public ApplicationConfigController(
ApplicationConfigService appConfigService,
ILogger<ApplicationConfigController> logger,
IEmailTemplateRepository emailTemplateRepository)
ApplicationConfigService appConfigService,
IEmailTemplateRepository emailTemplateRepository, SaaSClientLogger<ApplicationConfigController> logger)
{
this.appConfigService = appConfigService;
this.emailTemplateRepository = emailTemplateRepository;
Expand Down Expand Up @@ -198,4 +197,6 @@ public IActionResult PostUpload(List<IFormFile> files)
return RedirectToAction("Index");
}



}
10 changes: 6 additions & 4 deletions src/AdminSite/Controllers/ApplicationLogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ namespace Marketplace.SaaS.Accelerator.AdminSite.Controllers;
[ServiceFilter(typeof(KnownUserAttribute))]
public class ApplicationLogController : BaseController
{
private readonly ILogger<ApplicationLogController> logger;
private readonly SaaSClientLogger<ApplicationLogController> logger;

private ApplicationLogService appLogService;

private readonly IApplicationLogRepository appLogRepository;

public ApplicationLogController(IApplicationLogRepository applicationLogRepository, ILogger<ApplicationLogController> logger)
public ApplicationLogController(IApplicationLogRepository applicationLogRepository, SaaSClientLogger<ApplicationLogController> logger)
{
this.appLogRepository = applicationLogRepository;
this.logger = logger;
appLogService = new ApplicationLogService(this.appLogRepository);
}
public IActionResult Index()
{
this.logger.LogInformation("Application Log Controller / Index");
this.logger.Info("Application Log Controller / Index");
try
{
List<ApplicationLog> getAllAppLogData = this.appLogService.GetAllLogs().OrderByDescending(appLog => appLog.ActionTime).ToList();
Expand All @@ -37,8 +37,10 @@ public IActionResult Index()
}
catch (Exception ex)
{
this.logger.LogError(ex, ex.Message);
this.logger.LogError($"Message:{ex.Message} :: {ex.InnerException}");
return this.View("Error", ex);
}
}


}
3 changes: 3 additions & 0 deletions src/AdminSite/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Web;
using Marketplace.SaaS.Accelerator.Services.Models;
using Marketplace.SaaS.Accelerator.Services.Utilities;
using Microsoft.AspNetCore.Authentication;
Expand All @@ -16,6 +17,7 @@ public class BaseController : Controller
/// <summary>
/// Initializes a new instance of the <see cref="BaseController" /> class.
/// </summary>
///
public BaseController()
{
this.CheckAuthentication();
Expand Down Expand Up @@ -79,4 +81,5 @@ public IActionResult CheckAuthentication()
return this.RedirectToAction("Index", "Home", new { });
}
}

}
114 changes: 59 additions & 55 deletions src/AdminSite/Controllers/HomeController.cs

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions src/AdminSite/Controllers/KnownUsersController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Web;
using Marketplace.SaaS.Accelerator.DataAccess.Contracts;
using Marketplace.SaaS.Accelerator.DataAccess.Entities;
using Marketplace.SaaS.Accelerator.Services.Utilities;
Expand All @@ -15,15 +16,15 @@ namespace Marketplace.SaaS.Accelerator.AdminSite.Controllers;
public class KnownUsersController : BaseController
{
private readonly IKnownUsersRepository knownUsersRepository;
private readonly ILogger<OffersController> logger;
private readonly SaaSClientLogger<KnownUsersController> logger;

/// <summary>
/// Initializes a new instance of the <see cref="KnownUsersController" /> class.
/// </summary>
/// <param name = "knownUsersRepository" > The known users repository.</param>
/// <param name="logger">The logger.</param>

public KnownUsersController(IKnownUsersRepository knownUsersRepository, ILogger<OffersController> logger)
public KnownUsersController(IKnownUsersRepository knownUsersRepository, SaaSClientLogger<KnownUsersController> logger)
{
this.knownUsersRepository = knownUsersRepository;
this.logger = logger;
Expand All @@ -35,15 +36,15 @@ public KnownUsersController(IKnownUsersRepository knownUsersRepository, ILogger<
/// <returns>All known users.</returns>
public IActionResult Index()
{
this.logger.LogInformation("KnownUsers Controller / Index");
this.logger.Info("KnownUsers Controller / Index");
try
{
var getAllKnownUsers = this.knownUsersRepository.GetAllKnownUsers();
return this.View(getAllKnownUsers);
}
catch (Exception ex)
{
this.logger.LogError(ex, ex.Message);
this.logger.LogError($"Message:{ex.Message} :: {ex.InnerException}");
return this.View("Error", ex);
}
}
Expand All @@ -56,15 +57,17 @@ public IActionResult Index()
public JsonResult SaveKnownUsers([FromBody] IEnumerable<KnownUsers> knownUsers)
{

this.logger.LogInformation("KnownUsers Controller / SaveKnownUsers");
this.logger.Info("KnownUsers Controller / SaveKnownUsers");
try
{
return Json(this.knownUsersRepository.SaveAllKnownUsers(knownUsers));
}
catch (Exception ex)
{
this.logger.LogError(ex, ex.Message);
this.logger.LogError($"Message:{ex.Message} :: {ex.InnerException}");
return Json(string.Empty);
}
}


}
20 changes: 11 additions & 9 deletions src/AdminSite/Controllers/OffersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Web;
using Marketplace.SaaS.Accelerator.AdminSite.Models.Offers;
using Marketplace.SaaS.Accelerator.DataAccess.Context;
using Marketplace.SaaS.Accelerator.DataAccess.Contracts;
Expand All @@ -28,7 +29,7 @@ public class OffersController : BaseController

private readonly IOfferAttributesRepository offersAttributeRepository;

private readonly ILogger<OffersController> logger;
private readonly SaaSClientLogger<OffersController> logger;

private readonly OffersService offersService;

Expand All @@ -48,8 +49,7 @@ public OffersController(
IApplicationConfigRepository applicationConfigRepository,
IUsersRepository usersRepository,
IValueTypesRepository valueTypesRepository,
IOfferAttributesRepository offersAttributeRepository,
ILogger<OffersController> logger)
IOfferAttributesRepository offersAttributeRepository, SaaSClientLogger<OffersController> logger)
{
this.applicationConfigRepository = applicationConfigRepository;
this.usersRepository = usersRepository;
Expand All @@ -66,7 +66,7 @@ public OffersController(
/// <returns>return All subscription.</returns>
public IActionResult Index()
{
this.logger.LogInformation("Offers Controller / Index");
this.logger.Info("Offers Controller / Index");
try
{
this.TempData["ShowWelcomeScreen"] = "True";
Expand All @@ -90,7 +90,7 @@ public IActionResult Index()
}
catch (Exception ex)
{
this.logger.LogError(ex, ex.Message);
this.logger.LogError($"Message:{ex.Message} :: {ex.InnerException}");
return this.View("Error", ex);
}
}
Expand All @@ -104,7 +104,7 @@ public IActionResult Index()
/// </returns>
public IActionResult OfferDetails(Guid offerGuid)
{
this.logger.LogInformation("Offers Controller / OfferDetails: offerGuid {0}", offerGuid);
this.logger.Info("Offers Controller / OfferDetails: offerGuid {offerGuid}");

try
{
Expand Down Expand Up @@ -133,7 +133,7 @@ public IActionResult OfferDetails(Guid offerGuid)
}
catch (Exception ex)
{
this.logger.LogError("Message:{0} :: {1} ", ex.Message, ex.InnerException);
this.logger.LogError($"Message:{ex.Message} :: {ex.InnerException}");
return this.View("Error", ex);
}
}
Expand All @@ -149,7 +149,7 @@ public IActionResult OfferDetails(Guid offerGuid)
[ValidateAntiForgeryToken]
public IActionResult OfferDetails(OfferModel offersData)
{
this.logger.LogInformation("Offers Controller / OfferDetails: offerGuid {0}", JsonSerializer.Serialize(offersData));
this.logger.Info(HttpUtility.HtmlEncode($"Offers Controller / OfferDetails: offerGuid {JsonSerializer.Serialize(offersData)}"));
try
{
var currentUserDetail = this.usersRepository.GetPartnerDetailFromEmail(this.CurrentUserEmailAddress);
Expand Down Expand Up @@ -193,7 +193,7 @@ public IActionResult OfferDetails(OfferModel offersData)
}
catch (Exception ex)
{
this.logger.LogError(ex, ex.Message);
this.logger.LogError($"Message:{ex.Message} :: {ex.InnerException}");
return this.View("Error", ex);
}
}
Expand Down Expand Up @@ -222,4 +222,6 @@ private static OfferAttributesModel MapOfferAttributesModel(OfferAttributes offe
};
}



}
19 changes: 11 additions & 8 deletions src/AdminSite/Controllers/PlansController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Web;
using Marketplace.SaaS.Accelerator.DataAccess.Contracts;
using Marketplace.SaaS.Accelerator.Services.Models;
using Marketplace.SaaS.Accelerator.Services.Services;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class PlansController : BaseController

private readonly IOfferAttributesRepository offerAttributeRepository;

private readonly ILogger<PlansController> logger;
private readonly SaaSClientLogger<PlansController> logger;

private PlanService plansService;

Expand All @@ -50,7 +51,7 @@ public class PlansController : BaseController
/// <param name="offerAttributeRepository">The offer attribute repository.</param>
/// <param name="offerRepository">The offer repository.</param>
/// <param name="logger">The logger.</param>
public PlansController(ISubscriptionsRepository subscriptionRepository, IUsersRepository usersRepository, IApplicationConfigRepository applicationConfigRepository, IPlansRepository plansRepository, IOfferAttributesRepository offerAttributeRepository, IOffersRepository offerRepository, ILogger<PlansController> logger)
public PlansController(ISubscriptionsRepository subscriptionRepository, IUsersRepository usersRepository, IApplicationConfigRepository applicationConfigRepository, IPlansRepository plansRepository, IOfferAttributesRepository offerAttributeRepository, IOffersRepository offerRepository, SaaSClientLogger<PlansController> logger)
{
this.subscriptionRepository = subscriptionRepository;
this.usersRepository = usersRepository;
Expand All @@ -68,7 +69,7 @@ public PlansController(ISubscriptionsRepository subscriptionRepository, IUsersRe
/// <returns>return All subscription.</returns>
public IActionResult Index()
{
this.logger.LogInformation("Plans Controller / OfferDetails: offerGuId");
this.logger.Info("Plans Controller / OfferDetails: offerGuId");
try
{
List<PlansModel> getAllPlansData = new List<PlansModel>();
Expand All @@ -82,7 +83,7 @@ public IActionResult Index()
}
catch (Exception ex)
{
this.logger.LogError(ex, ex.Message);
this.logger.LogError($"Message:{ex.Message} :: {ex.InnerException}");
return this.View("Error", ex);
}
}
Expand All @@ -96,7 +97,7 @@ public IActionResult Index()
/// </returns>
public IActionResult PlanDetails(Guid planGuId)
{
this.logger.LogInformation("Plans Controller / PlanDetails: planGuId {0}", planGuId);
this.logger.Info(HttpUtility.HtmlEncode($"Plans Controller / PlanDetails: planGuId {planGuId}"));
try
{
PlansModel plans = new PlansModel();
Expand All @@ -107,7 +108,7 @@ public IActionResult PlanDetails(Guid planGuId)
}
catch (Exception ex)
{
this.logger.LogError(ex, ex.Message);
this.logger.LogError($"Message:{ex.Message} :: {ex.InnerException}");
return this.View("Error", ex);
}
}
Expand All @@ -123,7 +124,7 @@ public IActionResult PlanDetails(Guid planGuId)
[ValidateAntiForgeryToken]
public IActionResult PlanDetails(PlansModel plans)
{
this.logger.LogInformation("Plans Controller / PlanDetails: plans {0}", JsonSerializer.Serialize(plans));
this.logger.Info(HttpUtility.HtmlEncode($"Plans Controller / PlanDetails: plans {JsonSerializer.Serialize(plans)}"));
try
{
var currentUserDetail = this.usersRepository.GetPartnerDetailFromEmail(this.CurrentUserEmailAddress);
Expand Down Expand Up @@ -154,8 +155,10 @@ public IActionResult PlanDetails(PlansModel plans)
}
catch (Exception ex)
{
this.logger.LogError(ex, ex.Message);
this.logger.LogError($"Message:{ex.Message} :: {ex.InnerException}");
return this.PartialView("Error", ex);
}
}


}
Loading

0 comments on commit f3fcf7c

Please sign in to comment.