Skip to content

Commit 256d880

Browse files
authored
Merge branch 'main' into bug/addSpecificViewerScopeForSelectedFiles
2 parents c12a38d + de96259 commit 256d880

File tree

8 files changed

+46
-8
lines changed

8 files changed

+46
-8
lines changed

app/common/src/main/java/stirling/software/common/service/UserServiceInterface.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ public interface UserServiceInterface {
55

66
String getCurrentUsername();
77

8+
String getCurrentUserApiKey();
9+
810
long getTotalUsersCount();
911

1012
boolean isCurrentUserAdmin();

app/core/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import stirling.software.SPDF.model.PipelineOperation;
3838
import stirling.software.SPDF.model.PipelineResult;
3939
import stirling.software.SPDF.service.ApiDocService;
40-
import stirling.software.common.model.enumeration.Role;
4140
import stirling.software.common.service.UserServiceInterface;
4241
import stirling.software.common.util.TempFile;
4342
import stirling.software.common.util.TempFileManager;
@@ -84,9 +83,35 @@ public static String removeTrailingNaming(String filename) {
8483
return name.substring(0, underscoreIndex) + extension;
8584
}
8685

86+
// Allowlist of URL path prefixes permitted through the pipeline.
87+
private static final List<String> ALLOWED_PIPELINE_PATH_PREFIXES =
88+
List.of(
89+
"/api/v1/general/",
90+
"/api/v1/misc/",
91+
"/api/v1/security/",
92+
"/api/v1/convert/",
93+
"/api/v1/filter/");
94+
95+
private void validatePipelineUrl(String url) {
96+
// Strip scheme+host to get the path portion for comparison
97+
String path = url;
98+
int schemeEnd = url.indexOf("://");
99+
if (schemeEnd != -1) {
100+
int pathStart = url.indexOf('/', schemeEnd + 3);
101+
path = pathStart != -1 ? url.substring(pathStart) : "/";
102+
}
103+
final String pathToCheck = path;
104+
boolean allowed = ALLOWED_PIPELINE_PATH_PREFIXES.stream().anyMatch(pathToCheck::contains);
105+
if (!allowed) {
106+
log.warn("Blocked pipeline request to disallowed URL: {}", url);
107+
throw new SecurityException(
108+
"Pipeline operation not permitted for endpoint: " + pathToCheck);
109+
}
110+
}
111+
87112
private String getApiKeyForUser() {
88113
if (userService == null) return "";
89-
return userService.getApiKeyForUser(Role.INTERNAL_API_USER.getRoleId());
114+
return userService.getCurrentUserApiKey();
90115
}
91116

92117
private String getBaseUrl() {
@@ -283,6 +308,7 @@ PipelineResult runPipelineAgainstFiles(List<Resource> outputFiles, PipelineConfi
283308

284309
/* package */ ResponseEntity<Resource> sendWebRequest(
285310
String url, MultiValueMap<String, Object> body) {
311+
validatePipelineUrl(url);
286312
RestTemplate restTemplate = new RestTemplate();
287313
// Set up headers, including API key
288314
HttpHeaders headers = new HttpHeaders();

app/core/src/test/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ public String getFilename() {
205205
});
206206
})) {
207207
ResponseEntity<Resource> response =
208-
pipelineProcessor.sendWebRequest("http://localhost/api", body);
208+
pipelineProcessor.sendWebRequest(
209+
"http://localhost/api/v1/general/merge-pdfs", body);
209210

210211
assertNotNull(response);
211212
assertEquals(HttpStatus.OK, response.getStatusCode());

app/proprietary/src/main/java/stirling/software/proprietary/security/service/UserService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ public String getApiKeyForUser(String username) {
198198
return user.getApiKey();
199199
}
200200

201+
@Override
202+
public String getCurrentUserApiKey() {
203+
String username = getCurrentUsername();
204+
if (username == null || username.isEmpty()) {
205+
throw new IllegalStateException("Cannot determine calling user for API key lookup");
206+
}
207+
return getApiKeyForUser(username);
208+
}
209+
201210
public boolean isValidApiKey(String apiKey) {
202211
return userRepository.findByApiKey(apiKey).isPresent();
203212
}

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ext {
2828
springSecuritySamlVersion = "7.0.2"
2929
openSamlVersion = "5.2.1"
3030
commonmarkVersion = "0.27.1"
31-
googleJavaFormatVersion = "1.35.0"
31+
googleJavaFormatVersion = "1.28.0"
3232
logback = "1.5.32"
3333
junitPlatformVersion = "1.12.2"
3434
modernJavaVersion = 21
@@ -78,7 +78,7 @@ springBoot {
7878

7979
allprojects {
8080
group = 'stirling.software'
81-
version = '2.8.0'
81+
version = '2.9.0'
8282

8383
configurations.configureEach {
8484
exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat"

frontend/src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
33
"productName": "Stirling-PDF",
4-
"version": "2.8.0",
4+
"version": "2.9.0",
55
"identifier": "stirling.pdf.dev",
66
"build": {
77
"frontendDist": "../dist",

frontend/src/core/testing/serverExperienceSimulations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const FREE_LICENSE_INFO: LicenseInfo = {
3838

3939
const BASE_NO_LOGIN_CONFIG: AppConfig = {
4040
enableAnalytics: true,
41-
appVersion: '2.8.0',
41+
appVersion: '2.9.0',
4242
serverCertificateEnabled: false,
4343
enableAlphaFunctionality: false,
4444
serverPort: 8080,

frontend/src/proprietary/testing/serverExperienceSimulations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const FREE_LICENSE_INFO: LicenseInfo = {
4848

4949
const BASE_NO_LOGIN_CONFIG: AppConfig = {
5050
enableAnalytics: true,
51-
appVersion: '2.8.0',
51+
appVersion: '2.9.0',
5252
serverCertificateEnabled: false,
5353
enableAlphaFunctionality: false,
5454
enableDesktopInstallSlide: true,

0 commit comments

Comments
 (0)