<commit_before>/*
 * Zed Attack Proxy (ZAP) and its related class files.
 *
 * ZAP is an HTTP/HTTPS proxy for assessing web application security.
 *
 * Copyright 2012 The ZAP development team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.zaproxy.zap.extension.pscanrulesAlpha;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.htmlparser.jericho.Source;

import org.parosproxy.paros.Constant;
import org.parosproxy.paros.core.scanner.Alert;
import org.parosproxy.paros.network.HttpMessage;
import org.zaproxy.zap.extension.pscan.PassiveScanThread;
import org.zaproxy.zap.extension.pscan.PluginPassiveScanner;


/**
 * A class to passively scan response for application Source Code, using source code signatures
 * @author <EMAIL>
 *
 */
public class SourceCodeDisclosureScanner extends PluginPassiveScanner {

	private PassiveScanThread parent = null;
	
	/**
	 * a map of a regular expression pattern to the Programming language to which the pattern most likely corresponds
	 */
	static Map <Pattern, String> languagePatterns = new HashMap <Pattern, String> ();
	
	static {
		//PHP
		languagePatterns.put(Pattern.compile("<\\?php\\s*.+?;\\s*\\?>", Pattern.MULTILINE | Pattern.DOTALL), "PHP");
		languagePatterns.put(Pattern.compile("phpinfo\\s*\\(\\s*\\)"), "PHP");
		languagePatterns.put(Pattern.compile("\\$_POST\\s*\\["), "PHP");
		languagePatterns.put(Pattern.compile("\\$_GET\\s*\\["), "PHP");
		
		//JSP (Java based)
		languagePatterns.put(Pattern.compile("<%@\\s*page\\s+.+?%>", Pattern.MULTILINE | Pattern.DOTALL), "JSP");
		languagePatterns.put(Pattern.compile("<%@\\s*include.+?%>", Pattern.MULTILINE | Pattern.DOTALL), "JSP");
		languagePatterns.put(Pattern.compile("<%@\\s*taglib.+?%>", Pattern.MULTILINE | Pattern.DOTALL), "JSP");
		languagePatterns.put(Pattern.compile("<jsp:directive\\.page.+?>", Pattern.MULTILINE | Pattern.DOTALL), "JSP");<commit_msg>Remove pattern that causes false positives on PHP.<commit_after>/*
 * Zed Attack Proxy (ZAP) and its related class files.
 *
 * ZAP is an HTTP/HTTPS proxy for assessing web application security.
 *
 * Copyright 2012 The ZAP development team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.zaproxy.zap.extension.pscanrulesAlpha;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.htmlparser.jericho.Source;

import org.parosproxy.paros.Constant;
import org.parosproxy.paros.core.scanner.Alert;
import org.parosproxy.paros.network.HttpMessage;
import org.zaproxy.zap.extension.pscan.PassiveScanThread;
import org.zaproxy.zap.extension.pscan.PluginPassiveScanner;


/**
 * A class to passively scan response for application Source Code, using source code signatures
 * @author <EMAIL>
 *
 */
public class SourceCodeDisclosureScanner extends PluginPassiveScanner {

	private PassiveScanThread parent = null;
	
	/**
	 * a map of a regular expression pattern to the Programming language to which the pattern most likely corresponds
	 */
	static Map <Pattern, String> languagePatterns = new HashMap <Pattern, String> ();
	
	static {
		//PHP
		languagePatterns.put(Pattern.compile("<\\?php\\s*.+?;\\s*\\?>", Pattern.MULTILINE | Pattern.DOTALL), "PHP");
		//languagePatterns.put(Pattern.compile("phpinfo\\s*\\(\\s*\\)"), "PHP");  //features in "/index.php?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000", which is not a Source Code Disclosure issue.  
		languagePatterns.put(Pattern.compile("\\$_POST\\s*\\["), "PHP");
		languagePatterns.put(Pattern.compile("\\$_GET\\s*\\["), "PHP");
		
		//JSP (Java based)
		languagePatterns.put(Pattern.compile("<%@\\s*page\\s+.+?%>", Pattern.MULTILINE | Pattern.DOTALL), "JSP");
		languagePatterns.put(Pattern.compile("<%@\\s*include.+?%>", Pattern.MULTILINE | Pattern.DOTALL), "JSP");
		languagePatterns.put(Pattern.compile("<%@\\s*taglib.+?%>", Pattern.MULTILINE | Pattern.DOTALL), "JSP");
		languagePatterns.put(Pattern.compile("<jsp:directive\\.page.+?>", Pattern.MULTILINE | Pattern.DOTALL), "JSP");
{'fraction_non_alphanumeric': 0.14044289044289043, 'fraction_numerical': 0.007187257187257187, 'mean_word_length': 4.548491379310345, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6746704', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1572, 'n_words': 439}