Skip to content

Commit 80f120e

Browse files
committed
sanitize path and revision separately
1 parent aa22101 commit 80f120e

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/web/Laundromat.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
import java.util.stream.Stream;
3434

3535
/**
36-
* Represents a container for sanitizing methods for avoiding classifications as
37-
* taint bugs.
36+
* Represents a container for sanitizing methods for avoiding classifications as taint bugs.
3837
*/
3938
public class Laundromat {
4039

@@ -62,14 +61,26 @@ public static String launderServerName(String value) {
6261

6362
/**
6463
* Sanitize {@code value} where it will be used in subsequent OpenGrok
65-
* (non-logging) processing.
64+
* (non-logging) processing. The value is assumed to represent a revision string,
65+
* not including file path.
6666
* @return {@code null} if null or else {@code value} with anything besides
6767
* alphanumeric or {@code :} characters removed.
6868
*/
6969
public static String launderRevision(String value) {
7070
return replaceAll(value, "[^a-zA-Z0-9:]", "");
7171
}
7272

73+
/**
74+
* Sanitize {@code value} where it will be used in subsequent OpenGrok
75+
* (non-logging) processing. The value is assumed to represent a file path,
76+
* not necessarily existent.
77+
* @return {@code null} if null or else {@code value} with anything besides
78+
* alphanumeric or {@code :} characters removed.
79+
*/
80+
public static String launderPath(String value) {
81+
return replaceAll(value, ESC_N_R_T_F, "");
82+
}
83+
7384
/**
7485
* Sanitize {@code value} where it will be used in a Lucene query.
7586
* @return {@code null} if null or else {@code value} with "pattern-breaking

opengrok-web/src/main/java/org/opengrok/web/PageConfig.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,34 +232,31 @@ public String getHeaderData() {
232232
}
233233

234234
/**
235-
* Extract file path and revision strings from the URL.
236-
* @param data DiffData object
235+
* Extract file path and revision strings from the URI. Basically the request URI looks like this:
236+
* {@code http://$site/$webapp/diff/$resourceFile?r1=$fileA@$revA&r2=$fileB@$revB}
237+
* The code extracts file path and revision from the URI.
238+
* @param data DiffData object (output parameter)
237239
* @param context context path
238240
* @param filepath file path array (output parameter)
239241
* @return true if the extraction was successful, false otherwise
240242
* (in which case {@link DiffData#errorMsg} will be set)
241243
*/
242244
private boolean getFileRevision(DiffData data, String context, String[] filepath) {
243-
/*
244-
* Basically the request URI looks like this:
245-
* http://$site/$webapp/diff/$resourceFile?r1=$fileA@$revA&r2=$fileB@$revB
246-
* The code below extracts file path and revision from the URI.
247-
*/
248245
for (int i = 1; i <= 2; i++) {
249-
String p = Laundromat.launderRevision(req.getParameter(QueryParameters.REVISION_PARAM + i));
246+
String p = req.getParameter(QueryParameters.REVISION_PARAM + i);
250247
if (p != null) {
251248
int j = p.lastIndexOf("@");
252249
if (j != -1) {
253-
filepath[i - 1] = p.substring(0, j);
254-
data.rev[i - 1] = p.substring(j + 1);
250+
filepath[i - 1] = Laundromat.launderPath(p.substring(0, j));
251+
data.rev[i - 1] = Laundromat.launderRevision(p.substring(j + 1));
255252
}
256253
}
257254
}
258255

259256
if (data.rev[0] == null || data.rev[1] == null
260257
|| data.rev[0].isEmpty() || data.rev[1].isEmpty()
261258
|| data.rev[0].equals(data.rev[1])) {
262-
data.errorMsg = "Please pick two revisions to compare the changed "
259+
data.errorMsg = "Please pick two revisions to compare the changes "
263260
+ "from the <a href=\"" + context + Prefix.HIST_L
264261
+ getUriEncodedPath() + "\">history</a>";
265262
return false;

0 commit comments

Comments
 (0)