public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next) { // TODO: (mc) (core) Broken when setting is turned off :-/ // RE: Could you try again please? if (!_securitySettings.EnableHoneypotProtection) { await next(); return; } var isBot = _honeypotProtector.IsBot(); if (!isBot) { await next(); return; } else { _logger.Warn("Honeypot detected a bot and rejected the request."); var redirectUrl = _webHelper.GetCurrentPageUrl(true); context.Result = new RedirectResult(redirectUrl); } }
public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next) { if (!_securitySettings.EnableHoneypotProtection) { await next(); return; } var isBot = _honeypotProtector.IsBot(); if (!isBot) { await next(); return; } else { _logger.Warn("Honeypot detected a bot and rejected the request."); var redirectUrl = _webHelper.GetCurrentPageUrl(true); context.Result = new RedirectResult(redirectUrl); } }
public async Task Invoke(HttpContext context, IWebHelper webHelper, IWorkContext workContext) { using (LogContext.PushProperty("CustomerId", workContext.CurrentCustomer?.Id)) using (LogContext.PushProperty("UserName", context.User.Identity.Name)) using (LogContext.PushProperty("Url", webHelper.GetCurrentPageUrl(true))) using (LogContext.PushProperty("Referrer", webHelper.GetUrlReferrer())) using (LogContext.PushProperty("HttpMethod", context?.Request.Method)) using (LogContext.PushProperty("Ip", webHelper.GetClientIpAddress().ToString())) { await _next.Invoke(context); } }
public void OnAuthorization(AuthorizationFilterContext context) { if (!_securitySettings.EnableHoneypotProtection) { return; } var isBot = _honeypotProtector.IsBot(); if (!isBot) { return; } _logger.Warn("Honeypot detected a bot and rejected the request."); var redirectUrl = _webHelper.GetCurrentPageUrl(true); context.Result = new RedirectResult(redirectUrl); }
private void DoTrack(ActionExecutingContext context) { if (!HttpMethods.IsGet(context.HttpContext.Request.Method)) { return; } var customer = _workContext.CurrentCustomer; if (customer == null || customer.Deleted || customer.IsSystemAccount) { return; } bool dirty = false; // Last activity date if (_attribute.TrackDate && customer.LastActivityDateUtc.AddMinutes(1.0) < DateTime.UtcNow) { customer.LastActivityDateUtc = DateTime.UtcNow; dirty = true; } // Last IP address if (_attribute.TrackIpAddress && _privacySettings.StoreLastIpAddress) { var currentIpAddress = _webHelper.GetClientIpAddress().ToString(); if (currentIpAddress.HasValue()) { customer.LastIpAddress = currentIpAddress; dirty = true; } } // Last visited page if (_attribute.TrackPage && _customerSettings.StoreLastVisitedPage) { var currentUrl = _webHelper.GetCurrentPageUrl(true); if (currentUrl.HasValue()) { customer.GenericAttributes.LastVisitedPage = currentUrl; dirty = true; } } // Last user agent if (_attribute.TrackUserAgent && _customerSettings.StoreLastVisitedPage) { // TODO: (core) Make new setting CustomerSettings.StoreLastUserAgent var currentUserAgent = _userAgent.RawValue; if (currentUserAgent.HasValue()) { customer.LastUserAgent = currentUserAgent; dirty = true; } } if (dirty) { _db.TryUpdate(customer); } }