mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-09-08 17:51:20 +02:00
Update GeneralUtils.java
This commit is contained in:
parent
768f695f6b
commit
d395ce6a4f
@ -444,14 +444,24 @@ public class GeneralUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts a file from classpath:/static/python to a temporary directory and returns the
|
* Extracts a file from classpath:/static/python to a temporary directory and returns the path.
|
||||||
* path.
|
*/
|
||||||
*/
|
|
||||||
public static Path extractScript(String scriptName) throws IOException {
|
public static Path extractScript(String scriptName) throws IOException {
|
||||||
// Validate input
|
// Validate input
|
||||||
if (scriptName == null || scriptName.trim().isEmpty()) {
|
if (scriptName == null || scriptName.trim().isEmpty()) {
|
||||||
throw new IllegalArgumentException("scriptName must not be null or empty");
|
throw new IllegalArgumentException("scriptName must not be null or empty");
|
||||||
}
|
}
|
||||||
|
if (scriptName.contains("..") || scriptName.contains("/")) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"scriptName must not contain path traversal characters");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> validScripts = Arrays.asList("png_to_webp.py", "split_photos.py");
|
||||||
|
|
||||||
|
if (!validScripts.contains(scriptName)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"scriptName must be either 'png_to_webp.py' or 'split_photos.py'");
|
||||||
|
}
|
||||||
// 1. load the script from classpath
|
// 1. load the script from classpath
|
||||||
ClassPathResource resource = new ClassPathResource("static/python/" + scriptName);
|
ClassPathResource resource = new ClassPathResource("static/python/" + scriptName);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user