0
我在我的應用程序中看到此代碼。有人可以幫我理解這是如何幫助清理請求URL以防止任何由CR/LF引起的攻擊嗎?清潔網址以防止由於CR引起的攻擊LF
public static String validaterequestURL(String requestURL) throws EncodingException {
Encoder encoder = new DefaultEncoder(new ArrayList<String>());
//canonicalize
String clean = encoder.canonicalize(requestURL).trim();
clean = encoder.decodeFromrequestURL(clean);
int idxR = clean.indexOf('\r');
int idxN = clean.indexOf('\n');
if(idxN >= 0 || idxR>=0){
if(idxN>idxR){
clean = clean.substring(0,idxN-1);
}
else{
clean = clean.substring(0,idxR-1);
}
}
return clean;
}
我特別想了解下面幾行是如何工作的?
int idxR = clean.indexOf('\r');
int idxN = clean.indexOf('\n');
if(idxN >= 0 || idxR>=0){
if(idxN>idxR){
clean = clean.substring(0,idxN-1);
}
else{
clean = clean.substring(0,idxR-1);
}
}