diff --git a/csharp/src/security/CWE-287/FormsAuthTicketProtectionDisabled.qhelp b/csharp/src/security/CWE-287/FormsAuthTicketProtectionDisabled.qhelp new file mode 100644 index 00000000..d6e3b926 --- /dev/null +++ b/csharp/src/security/CWE-287/FormsAuthTicketProtectionDisabled.qhelp @@ -0,0 +1,85 @@ + + + + +

+ASP.NET forms authentication keeps the identity of the signed-in user in an authentication ticket, +which is sent to the browser in a cookie. The protection attribute of the +<forms> element in Web.config controls how the ticket is protected. +The value None turns off both encryption and validation, so anyone who can set the +cookie can create or change a ticket and act as any user, including an administrator. +

+
+ + +

+Use protection="All", or remove the protection attribute because +All is the default. It encrypts the ticket and validates it with a message +authentication code. +

+
+ + +

+The following configuration turns off the protection of the forms authentication ticket: +

+ + + + + + +]]> + +

+The following configuration encrypts and validates the ticket: +

+ + + + + + +]]> +
+ +
+ +
+ + +
  • Microsoft Learn: forms Element for authentication (ASP.NET Settings Schema).
  • +
  • Microsoft Learn: authentication Element (ASP.NET Settings Schema).
  • +
  • Microsoft Learn: FormsProtectionEnum Enum.
  • +
    + +
    diff --git a/csharp/src/security/CWE-287/FormsAuthTicketProtectionDisabled.ql b/csharp/src/security/CWE-287/FormsAuthTicketProtectionDisabled.ql new file mode 100644 index 00000000..5e077e1e --- /dev/null +++ b/csharp/src/security/CWE-287/FormsAuthTicketProtectionDisabled.ql @@ -0,0 +1,47 @@ +/** + * @name Forms authentication ticket protection disabled + * @description Setting 'protection' to 'None' on the forms authentication element disables both + * encryption and validation of the forms authentication ticket, so an attacker can + * forge or tamper with the ticket and impersonate any user. + * @kind problem + * @id githubsecuritylab/cs/forms-auth-ticket-protection-disabled + * @problem.severity error + * @security-severity 8.1 + * @precision high + * @tags security + * experimental + * external/cwe/cwe-287 + */ + +import csharp +import semmle.code.asp.WebConfig + +/** + * Holds if `file` is a `Web.config` file or a `Web..config` transformation file. A copy + * under another name, such as `Web - Copy.config`, and an application configuration, such as + * `Program.exe.config`, are not used for the authentication settings of a web application. + */ +private predicate isWebConfigFile(XmlFile file) { + exists(string name | name = file.getBaseName().toLowerCase() | + name = "web.config" or name.matches("web.%.config") + ) +} + +/** + * Holds if forms authentication is the authentication mode of the `` element + * that contains `forms`. The default mode is `Windows`, and forms authentication is only active + * in `Forms` mode. + */ +private predicate isFormsAuthenticationMode(FormsElement forms) { + forms.getParent().(XmlElement).getAttribute("mode").getValue() = "Forms" +} + +from FormsElement forms, XmlAttribute protection +where + isWebConfigFile(forms.getFile()) and + isFormsAuthenticationMode(forms) and + protection = forms.getAttribute("protection") and + // The runtime rejects other spellings, such as `none` or ` None `, as an invalid configuration. + protection.getValue() = "None" +select protection, + "The forms authentication ticket is neither encrypted nor validated because 'protection' is set to 'None'." diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/FormsAuthTicketProtectionDisabled.expected b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/FormsAuthTicketProtectionDisabled.expected new file mode 100644 index 00000000..9337eb30 --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/FormsAuthTicketProtectionDisabled.expected @@ -0,0 +1,4 @@ +| Unprotected/Web.config:5:7:5:74 | protection=None | The forms authentication ticket is neither encrypted nor validated because 'protection' is set to 'None'. | +| UnprotectedInLocation/Web.config:6:9:6:53 | protection=None | The forms authentication ticket is neither encrypted nor validated because 'protection' is set to 'None'. | +| UnprotectedNamespaced/Web.config:5:7:5:61 | protection=None | The forms authentication ticket is neither encrypted nor validated because 'protection' is set to 'None'. | +| UnprotectedTransform/Web.Release.config:5:7:5:61 | protection=None | The forms authentication ticket is neither encrypted nor validated because 'protection' is set to 'None'. | diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/FormsAuthTicketProtectionDisabled.qlref b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/FormsAuthTicketProtectionDisabled.qlref new file mode 100644 index 00000000..020a64fc --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/FormsAuthTicketProtectionDisabled.qlref @@ -0,0 +1 @@ +query: security/CWE-287/FormsAuthTicketProtectionDisabled.ql diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/InvalidSpelling/Web.config b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/InvalidSpelling/Web.config new file mode 100644 index 00000000..89949160 --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/InvalidSpelling/Web.config @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/Misplaced/Web.config b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/Misplaced/Web.config new file mode 100644 index 00000000..b84acf98 --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/Misplaced/Web.config @@ -0,0 +1,17 @@ + + + + + + + + + + + + + diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/NotFormsMode/Web.config b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/NotFormsMode/Web.config new file mode 100644 index 00000000..a07e45a0 --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/NotFormsMode/Web.config @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/NotWebConfig/Program.exe.config b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/NotWebConfig/Program.exe.config new file mode 100644 index 00000000..37f75ee3 --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/NotWebConfig/Program.exe.config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/NotWebConfig/Web-Copy.config b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/NotWebConfig/Web-Copy.config new file mode 100644 index 00000000..e8b1cbc2 --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/NotWebConfig/Web-Copy.config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/Program.cs b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/Program.cs new file mode 100644 index 00000000..6f500e08 --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/Program.cs @@ -0,0 +1,4 @@ +class Program +{ + static void Main() { } +} diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/Protected/Web.config b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/Protected/Web.config new file mode 100644 index 00000000..3d656713 --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/Protected/Web.config @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/Unprotected/Web.config b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/Unprotected/Web.config new file mode 100644 index 00000000..d61a5d0d --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/Unprotected/Web.config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/UnprotectedInLocation/Web.config b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/UnprotectedInLocation/Web.config new file mode 100644 index 00000000..bb0f77d3 --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/UnprotectedInLocation/Web.config @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/UnprotectedNamespaced/Web.config b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/UnprotectedNamespaced/Web.config new file mode 100644 index 00000000..0fe6c0ce --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/UnprotectedNamespaced/Web.config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/UnprotectedTransform/Web.Release.config b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/UnprotectedTransform/Web.Release.config new file mode 100644 index 00000000..21062cd1 --- /dev/null +++ b/csharp/test/security/CWE-287/FormsAuthTicketProtectionDisabled/UnprotectedTransform/Web.Release.config @@ -0,0 +1,8 @@ + + + + + + + +