forked from yeshodha02/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruleset_j2ee.xml
More file actions
328 lines (305 loc) · 10.3 KB
/
ruleset_j2ee.xml
File metadata and controls
328 lines (305 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<?xml version="1.0"?>
<ruleset name="Rule Set - J2EE/Web"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>These are the rules by which J2EE/Web Applications will be built. </description>
<!-- Priorities
HIGH :1
MEDIUM_HIGH:2
MEDIUM:3
MEDIUM_LOW:4
LOW : 5
-->
<rule ref="rulesets/java/j2ee.xml/UseProperClassLoader"> <priority>3</priority></rule>
<rule ref="rulesets/java/j2ee.xml/DoNotCallSystemExit"> <priority>3</priority></rule>
<rule ref="rulesets/java/j2ee.xml/DoNotUseThreads"> <priority>3</priority></rule>
<rule name="NoLongScripts" language="jsp" since="3.6"
message="Avoid having long scripts (e.g. Javascript) inside a JSP file."
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoLongScripts">
<description>
Scripts should be part of Tag Libraries, rather than part of JSP pages.
</description>
<priority>2</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
// HtmlScript [ (@EndLine - @BeginLine > 10) ]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
<HTML>
<BODY>
<!--Java Script-->
<SCRIPT language="JavaScript" type="text/javascript">
<!--
function calcDays(){
var date1 = document.getElementById('d1').lastChild.data;
var date2 = document.getElementById('d2').lastChild.data;
date1 = date1.split("-");
date2 = date2.split("-");
var sDate = new Date(date1[0]+"/"+date1[1]+"/"+date1[2]);
var eDate = new Date(date2[0]+"/"+date2[1]+"/"+date2[2]);
var daysApart = Math.abs(Math.round((sDate-eDate)/86400000));
document.getElementById('diffDays').lastChild.data = daysApart;
}
onload=calcDays;
//-->
</SCRIPT>
</BODY>
</HTML>
]]>
</example>
</rule>
<rule name="NoScriptlets" language="jsp" since="3.6"
message="Avoid having scriptlets inside a JSP file."
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoScriptlets">
<description>
Scriptlets should be factored into Tag Libraries or JSP declarations, rather than being part of JSP pages.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//JspScriptlet
|
//Element[ upper-case(@Name)="JSP:SCRIPTLET" ]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
<HTML>
<HEAD>
<%
response.setHeader("Pragma", "No-cache");
%>
</HEAD>
<BODY>
<jsp:scriptlet>String title = "Hello world!";</jsp:scriptlet>
</BODY>
</HTML>
]]>
</example>
</rule>
<rule name="NoInlineStyleInformation" since="3.6"
message="Avoid having style information in JSP files."
class="net.sourceforge.pmd.lang.jsp.rule.basic.NoInlineStyleInformationRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoInlineStyleInformation">
<description><![CDATA[
Style information should be put in CSS files, not in JSPs. Therefore, don't use <B> or <FONT> tags, or attributes like "align='center'". ]]>
</description>
<priority>3</priority>
<example>
<![CDATA[
<html><body><p align='center'><b>text</b></p></body></html>
]]>
</example>
</rule>
<rule name="NoClassAttribute" language="jsp" since="3.6"
message="Do not use an attribute called 'class'."
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoClassAttribute">
<description>
Do not use an attribute called 'class'. Use "styleclass" for CSS styles.
</description>
<priority>2</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[ //Attribute[ upper-case(@Name)="CLASS" ] ]]>
</value>
</property>
</properties>
<example>
<![CDATA[
<HTML> <BODY>
<P class="MajorHeading">Some text</P>
</BODY> </HTML>
]]>
</example>
</rule>
<rule name="NoJspForward" language="jsp" since="3.6"
message="Do not do a forward from within a JSP file."
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoJspForward">
<description>
Do not do a forward from within a JSP file.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[ //Element[ @Name="jsp:forward" ] ]]>
</value>
</property>
</properties>
<example>
<![CDATA[
<jsp:forward page='UnderConstruction.jsp'/>
]]>
</example>
</rule>
<rule name="IframeMissingSrcAttribute" language="jsp" since="3.6"
message="IFrames must have a src attribute."
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#IframeMissingSrcAttribute">
<description>
IFrames which are missing a src element can cause security information popups in IE if you are accessing the page
through SSL. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q261188
</description>
<priority>2</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//Element[upper-case(@Name)="IFRAME"][count(Attribute[upper-case(@Name)="SRC" ]) = 0]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
<HTML><title>bad example><BODY>
<iframe></iframe>
</BODY> </HTML>
<HTML><title>good example><BODY>
<iframe src="foo"></iframe>
</BODY> </HTML>
]]>
</example>
</rule>
<rule name="NoHtmlComments" language="jsp" since="3.6"
message="Use JSP comments instead of HTML comments"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoHtmlComments">
<description>
In a production system, HTML comments increase the payload
between the application server to the client, and serve
little other purpose. Consider switching to JSP comments.
</description>
<priority>2</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//CommentTag
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
<HTML><title>bad example><BODY>
<!-- HTML comment -->
</BODY> </HTML>
<HTML><title>good example><BODY>
<%-- JSP comment --%>
</BODY> </HTML>
]]>
</example>
</rule>
<rule name="DuplicateJspImports" since="3.7"
message="Avoid duplicate imports such as ''{0}''"
class="net.sourceforge.pmd.lang.jsp.rule.basic.DuplicateJspImportsRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#DuplicateJspImports">
<description><![CDATA[Avoid duplicate import statements inside JSP's. ]]>
</description>
<priority>3</priority>
<example>
<![CDATA[
<%@ page import=\"com.foo.MyClass,com.foo.MyClass\"%><html><body><b><img src=\"<%=Some.get()%>/foo\">xx</img>text</b></body></html>
]]>
</example>
</rule>
<rule name="JspEncoding" language="jsp" since="4.0"
class="net.sourceforge.pmd.lang.rule.XPathRule"
message="JSP file should use UTF-8 encoding"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#JspEncoding">
<description>
<![CDATA[
A missing 'meta' tag or page directive will trigger this rule, as well as a non-UTF-8 charset.
]]>
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//Content[
not(Element[@Name="meta"][
Attribute[@Name="content"]/AttributeValue[contains(lower-case(@Image),"charset=utf-8")]
])
and
not(JspDirective[@Name='page']/JspDirectiveAttribute[@Name='contentType'][contains(lower-case(@Value),"charset=utf-8")])
]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
Most browsers should be able to interpret the following headers:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
]]>
</example>
</rule>
<rule
name="NoInlineScript" language="jsp" since="4.0"
class="net.sourceforge.pmd.lang.rule.XPathRule"
message="Avoiding inlining HTML script content"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoInlineScript">
<description>
<![CDATA[
Avoid inlining HTML script content. Consider externalizing the HTML script using the 'src' attribute on the <script> element.
Externalized script could be reused between pages. Browsers can also cache the script, reducing overall download bandwidth.
]]>
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//HtmlScript[@Image != '']
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
Most browsers should be able to interpret the following headers:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
]]>
</example>
</rule>
<rule
name="NoUnsanitizedJSPExpression" since="5.1.4"
class="net.sourceforge.pmd.lang.jsp.rule.basic.NoUnsanitizedJSPExpressionRule"
message="Using unsanitized JSP expression can lead to Cross Site Scripting (XSS) attacks"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoUnsanitizedJSPExpression">
<description>
Avoid using expressions without escaping / sanitizing. This could lead to cross site scripting - as the expression
would be interpreted by the browser directly (e.g. "<script>alert('hello');</script>").
</description>
<priority>3</priority>
<example>
<![CDATA[
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
${expression} <!-- don't use this -->
${fn:escapeXml(expression)} <!-- instead, escape it -->
<c:out value="${expression}" /> <!-- or use c:out -->
]]>
</example>
</rule>
</ruleset>