@@ -47,6 +47,9 @@ public class HardcodedCredentialsCheck extends SimpleXPathBasedCheck {
4747 private static final XPathExpression WEB_CONFIG_CREDENTIALS_PATH = XPathBuilder
4848 .forExpression ("/configuration/system.web/authentication[@mode=\" Forms\" ]/forms/credentials[@passwordFormat=\" Clear\" ]/user/@password[string-length(.) > 0]" ).build ();
4949
50+ private static final XPathExpression WEB_CONFIG_APP_SETTINGS_ADD_PATH =
51+ XPathBuilder .forExpression ("//appSettings/add" ).build ();
52+
5053 private static final Pattern VALID_CREDENTIAL_VALUES = Pattern .compile ("[\\ {$#]\\ {" );
5154 private static final Pattern VALID_WEB_CONFIG_CREDENTIAL_VALUES = Pattern .compile ("^__.*__$" );
5255
@@ -80,6 +83,9 @@ public void scanFile(XmlFile file) {
8083 evaluateAsList (WEB_CONFIG_CREDENTIALS_PATH , file .getDocument ()).stream ()
8184 .filter (passwordAttrNode -> !isValidWebConfigCredential (passwordAttrNode .getNodeValue ()))
8285 .forEach (this ::reportIssue );
86+ evaluateAsList (WEB_CONFIG_APP_SETTINGS_ADD_PATH , file .getDocument ()).stream ()
87+ .filter (HardcodedCredentialsCheck ::isAddWithPassword )
88+ .forEach (this ::reportIssue );
8389 } else {
8490 checkElements (file .getDocument ());
8591 checkSpecialCases (file );
@@ -152,6 +158,16 @@ private static boolean isValidWebConfigCredential(String candidate) {
152158 return isValidCredential (candidate ) || VALID_WEB_CONFIG_CREDENTIAL_VALUES .matcher (candidate ).matches ();
153159 }
154160
161+ /** Detects nodes with key="password" and "value" attributes. */
162+ private static boolean isAddWithPassword (Node node ) {
163+ NamedNodeMap attributes = node .getAttributes ();
164+ Optional <String > keyValueLowerCase =
165+ Optional .ofNullable (attributes .getNamedItem ("key" ))
166+ .map (Node ::getNodeValue )
167+ .map (String ::toLowerCase );
168+ return keyValueLowerCase .equals (Optional .of ("password" )) && attributes .getNamedItem ("value" ) != null ;
169+ }
170+
155171 private void checkSpecialCases (XmlFile file ) {
156172 specialCases .forEach (specialCase -> specialCase .accept (file ));
157173 }
0 commit comments