| | | 1 | | using System.Text.RegularExpressions; |
| | | 2 | | |
| | | 3 | | namespace AspxLint.Core.Rules; |
| | | 4 | | |
| | | 5 | | public sealed class Sec001ViewStateMacFalse : IRule |
| | | 6 | | { |
| | 203 | 7 | | public string Id => "SEC-001"; |
| | 28 | 8 | | public string Name => "EnableViewStateMac=\"false\" — risque de securite"; |
| | 25 | 9 | | public Severity Severity => Severity.Error; |
| | | 10 | | public string Description => |
| | 25 | 11 | | "Desactiver EnableViewStateMac expose a des attaques par injection de ViewState. Cette option ne doit jamais etr |
| | 46 | 12 | | public bool HasFix => true; |
| | | 13 | | |
| | 5 | 14 | | private static readonly Regex DetectRegex = new( |
| | 5 | 15 | | @"EnableViewStateMac\s*=\s*[""']?false[""']?", |
| | 5 | 16 | | RegexOptions.IgnoreCase | RegexOptions.Compiled); |
| | | 17 | | |
| | | 18 | | public IEnumerable<Issue> Detect(string content, string[] lines, RuleContext ctx) |
| | | 19 | | { |
| | | 20 | | for (int i = 0; i < lines.Length; i++) |
| | | 21 | | { |
| | | 22 | | foreach (Match m in DetectRegex.Matches(lines[i])) |
| | | 23 | | { |
| | | 24 | | yield return new Issue(Id, Name, Severity, |
| | | 25 | | i + 1, m.Index + 1, m.Value, |
| | | 26 | | "Retirer ou repasser EnableViewStateMac a true."); |
| | | 27 | | } |
| | | 28 | | } |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | public string? Fix(string content, RuleContext ctx) => |
| | 21 | 32 | | DetectRegex.Replace(content, "EnableViewStateMac=\"true\""); |
| | | 33 | | } |