-
-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/3.2.x' into develop
- Loading branch information
Showing
240 changed files
with
13,074 additions
and
7,733 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
common/src/main/java/org/fao/geonet/utils/FilePathChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//============================================================================= | ||
//=== Copyright (C) 2001-2005 Food and Agriculture Organization of the | ||
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) | ||
//=== and United Nations Environment Programme (UNEP) | ||
//=== | ||
//=== This library is free software; you can redistribute it and/or | ||
//=== modify it under the terms of the GNU Lesser General Public | ||
//=== License as published by the Free Software Foundation; either | ||
//=== version 2.1 of the License, or (at your option) any later version. | ||
//=== | ||
//=== This library is distributed in the hope that it will be useful, | ||
//=== but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
//=== Lesser General Public License for more details. | ||
//=== | ||
//=== You should have received a copy of the GNU Lesser General Public | ||
//=== License along with this library; if not, write to the Free Software | ||
//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
//=== | ||
//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
//=== Rome - Italy. email: GeoNetwork@fao.org | ||
//============================================================================== | ||
|
||
package org.fao.geonet.utils; | ||
|
||
import org.fao.geonet.exceptions.BadParameterEx; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* Utility class to validate a file path. | ||
* | ||
* @author josegar | ||
*/ | ||
public class FilePathChecker { | ||
|
||
/** | ||
* Checks that a file path is not absolute path and doesn't have .. characters, throwing an exception | ||
* in these cases. | ||
* | ||
* @param filePath | ||
* @throws Exception | ||
*/ | ||
public static void verify(String filePath) throws Exception { | ||
if (filePath.contains("..")) { | ||
throw new BadParameterEx( | ||
"Invalid character found in path.", | ||
filePath); | ||
} | ||
|
||
Path path = Paths.get(filePath); | ||
if (path.isAbsolute() || filePath.startsWith("/") || | ||
filePath.startsWith("://", 1)) { | ||
throw new SecurityException("Wrong filename"); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
common/src/main/java/org/fao/geonet/utils/NoOpEntityResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.fao.geonet.utils; | ||
|
||
import org.xml.sax.EntityResolver; | ||
import org.xml.sax.InputSource; | ||
|
||
import java.io.StringReader; | ||
|
||
public class NoOpEntityResolver implements EntityResolver { | ||
public InputSource resolveEntity(String publicId, String systemId) { | ||
return new InputSource(new StringReader("")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.