Exemple #1
0
        public void TestUnicodeDetection3()
        {
            const string testString = "ÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
            bool         result     = Formatting.ContainsUnicode(testString);

            Assert.IsFalse(result, "Unicode was detected.");
        }
Exemple #2
0
        public void TestUnicodeDetection2()
        {
            const string testString = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\n\n\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇ";

            bool result = Formatting.ContainsUnicode(testString);

            Assert.IsTrue(result, "Unicode was not detected.");
        }
Exemple #3
0
        public void SendChatMessage(string subverseName, string message)
        {
            if (message == null)
            {
                return;
            }

            message = message.Trim();

            if (message != String.Empty && !String.IsNullOrEmpty(subverseName))
            {
                // check if user is banned
                if (UserHelper.IsUserBannedFromSubverse(Context.User.Identity.Name, subverseName))
                {
                    // message won't be processed
                    // this is necessary because banning a user from a subverse doesn't kick them from chat
                    return;
                }

                // discard message if it contains unicode
                if (Formatting.ContainsUnicode(message))
                {
                    return;
                }

                // trim message to 200 characters
                if (message.Length > 200)
                {
                    message = message.Substring(0, 200);
                }

                // check if previous message from this user is in cache
                //if (messageCache.ContainsKey(name))
                //{
                //    // discard duplicate message and update timestamp
                //    if (message == messageCache[name].Item1)
                //    {
                //        messageCache.Remove(name);
                //        messageCache.Add(name, new Tuple<string, DateTime>(message, DateTime.UtcNow));
                //        return;
                //    }

                //    // check timestamp and discard if diff less than 5 seconds
                //    var timestamp = messageCache[name].Item2;
                //    if (timestamp.AddSeconds(5) < DateTime.UtcNow)
                //    {
                //        return;
                //    }
                //}
                //messageCache.Add(Context.User.Identity.Name, new Tuple<string, DateTime>(message, DateTime.UtcNow));

                var formattedMessage = Formatting.FormatMessage(message, true, true);

                //var htmlEncodedMessage = WebUtility.HtmlEncode(formattedMessage);

                Clients.Group(subverseName).appendChatMessage(Context.User.Identity.Name, formattedMessage);
            }
        }
Exemple #4
0
        public void TestUnicodeDetection1()
        {
            const string testString = "🆆🅰🆂 🅶🅴🆃🆃🅸🅽🅶 🅲🅰🆄🅶🅷🆃 🅿🅰🆁🆃 🅾🅵 🆈🅾🆄🆁 🅿🅻🅰🅽🅴";
            const string testStringWithoutUnicode = "was getting caught part of your plane";

            bool result = Formatting.ContainsUnicode(testString);

            Assert.IsTrue(result, "Unicode was not detected.");

            bool resultWithoutUnicode = Formatting.ContainsUnicode(testStringWithoutUnicode);

            Assert.IsFalse(resultWithoutUnicode, "Unicode was not detected.");
        }
        protected override RuleOutcome EvaluateRule(VoatRuleContext context)
        {
            UserSubmission userSubmission = context.PropertyBag.UserSubmission;

            if (userSubmission == null)
            {
                return(CreateOutcome(RuleResult.Denied, "The submission must not be null"));
            }
            if (String.IsNullOrEmpty(userSubmission.Subverse))
            {
                return(CreateOutcome(RuleResult.Denied, "A subverse must be provided"));
            }

            switch (userSubmission.Type)
            {
            case SubmissionType.Link:
                if (String.IsNullOrEmpty(userSubmission.Url))
                {
                    return(CreateOutcome(RuleResult.Denied, "A link submission must include a url"));
                }

                //Ensure user isn't submitting links as titles
                if (userSubmission.Title.Equals(userSubmission.Url, StringComparison.InvariantCultureIgnoreCase) || userSubmission.Url.Contains(userSubmission.Title))
                {
                    return(CreateOutcome(RuleResult.Denied, "Submission title may not be the same as the URL you are trying to submit. Why would you even think about doing this?! Why?"));
                }

                // make sure the input URI is valid
                if (!UrlUtility.IsUriValid(userSubmission.Url))
                {
                    return(CreateOutcome(RuleResult.Denied, "The url you are trying to submit is invalid"));
                }
                break;

            case SubmissionType.Text:
                break;
            }


            if (String.IsNullOrEmpty(userSubmission.Title))
            {
                return(CreateOutcome(RuleResult.Denied, "A text submission must include a title"));
            }
            if (Formatting.ContainsUnicode(userSubmission.Title))
            {
                return(CreateOutcome(RuleResult.Denied, "Submission title can not contain Unicode or unprintable characters"));
            }
            int minTitleLength = 5;

            if (userSubmission.Title.Length < minTitleLength)
            {
                return(CreateOutcome(RuleResult.Denied, $"A title may not be less than {minTitleLength} characters"));
            }
            // make sure the title isn't a url
            if (UrlUtility.IsUriValid(userSubmission.Title))
            {
                return(CreateOutcome(RuleResult.Denied, "Submission title is a url? Why would you even think about doing this?! Why?"));
            }
            //if context.Subverse is null this means that it can't be found/doesn't exist
            if (context.Subverse == null || userSubmission.Subverse.Equals("all", StringComparison.OrdinalIgnoreCase)) //<-- the all subverse actually exists? HA! (Putts: leaving this code in because it's rad)
            {
                return(CreateOutcome(RuleResult.Denied, "Subverse does not exist"));
            }

            //if (context.Subverse.IsAdminDisabled.HasValue && context.Subverse.IsAdminDisabled.Value)
            //{
            //    return CreateOutcome(RuleResult.Denied, "Submissions to disabled subverses are not allowed");
            //}

            return(base.EvaluateRule(context));
        }
Exemple #6
0
        public async Task <ActionResult> Submit(CreateSubmissionViewModel model)
        {
            //set this incase invalid submittal
            var userData = UserData;

            model.RequireCaptcha = userData.Information.CommentPoints.Sum < Settings.MinimumCommentPointsForCaptchaSubmission && !Settings.CaptchaDisabled;

            // abort if model state is invalid
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //Check Captcha
            if (model.RequireCaptcha)
            {
                var captchaSuccess = await ReCaptchaUtility.Validate(Request);

                if (!captchaSuccess)
                {
                    ModelState.AddModelError(string.Empty, "Incorrect recaptcha answer");
                    return(View("Submit"));
                }
            }

            //new pipeline
            var userSubmission = new Domain.Models.UserSubmission();

            userSubmission.Subverse = model.Subverse;
            userSubmission.Title    = model.Title;
            userSubmission.Content  = (model.Type == Domain.Models.SubmissionType.Text ? model.Content : null);
            userSubmission.Url      = (model.Type == Domain.Models.SubmissionType.Link ? model.Url : null);

            var q      = new CreateSubmissionCommand(userSubmission);
            var result = await q.Execute();

            if (result.Success)
            {
                // redirect to comments section of newly posted submission
                return(RedirectToRoute(
                           "SubverseCommentsWithSort_Short",
                           new
                {
                    submissionID = result.Response.ID,
                    subverseName = result.Response.Subverse
                }
                           ));
            }
            else
            {
                //Help formatting issues with unicode.
                if (Formatting.ContainsUnicode(model.Title))
                {
                    ModelState.AddModelError(string.Empty, "Voat has strip searched your title and removed it's unicode. Please verify you approve of what you see.");
                    model.Title = Formatting.StripUnicode(model.Title);
                }
                else
                {
                    ModelState.AddModelError(string.Empty, result.Message);
                }
                PreventSpamAttribute.Reset();
                return(View("Submit", model));
            }
        }