forked from appsmithorg/appsmith
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't disclose sensitive info in case of DuplicateKeyException (a…
…ppsmithorg#21568) (appsmithorg#21596) ## Description When data integrity is violated in the case of `DuplicateKeyException` sensitive information like Appsmith URI is exposed to error messages. This is a big security risk that needs to be fixed and any error message shouldn't display Appsmith server credentials. [RCA](appsmithorg#21568 (comment)) [Slack Thread](https://theappsmith.slack.com/archives/C0423TJFUJK/p1679082313650259) Fixes appsmithorg#21568 Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - Chore (housekeeping or task changes that don't impact user perception) ## How Has This Been Tested? - Manual - JUnit ### Test Plan > Add Testsmith test cases links that relate to this PR ### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test Co-authored-by: Aishwarya UR <[email protected]>
- Loading branch information
1 parent
9333cc3
commit 99b03f2
Showing
6 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
...-server/src/main/java/com/appsmith/server/exceptions/util/DuplicateKeyExceptionUtils.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,25 @@ | ||
package com.appsmith.server.exceptions.util; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
@Slf4j | ||
public class DuplicateKeyExceptionUtils { | ||
private final static Pattern pattern = Pattern.compile("dup key: \\{ .*:(.*)}'"); | ||
|
||
public static String extractConflictingObjectName(String duplicateKeyErrorMessage) { | ||
Matcher matcher = pattern.matcher(duplicateKeyErrorMessage); | ||
if (matcher.find()) { | ||
return matcher.group(1).trim(); | ||
} | ||
log.warn("DuplicateKeyException regex needs attention. It's unable to extract object name from the error message. Possible reason: the underlying library may have changed the format of the error message."); | ||
/* | ||
[Fallback strategy] | ||
AppsmithError.DUPLICATE_KEY has a placeholder where it expects the name of the object that conflicts with the existing names. | ||
In case the execution reaches here we don't want to render `null` rather the string returned as below will yet make the message look good. | ||
*/ | ||
return "that you provided"; | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/AppsmithErrorTest.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 |
---|---|---|
@@ -1,14 +1,34 @@ | ||
package com.appsmith.server.helpers; | ||
|
||
import com.appsmith.server.exceptions.AppsmithError; | ||
import com.appsmith.server.exceptions.util.DuplicateKeyExceptionUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.dao.DuplicateKeyException; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class AppsmithErrorTest { | ||
@Test | ||
public void verifyUniquenessOfAppsmithErrorCode() { | ||
assert (Arrays.stream(AppsmithError.values()).map(AppsmithError::getAppErrorCode).distinct().count() == AppsmithError.values().length); | ||
} | ||
|
||
@Test | ||
public void verifyDuplicateKeyExceptionDoesnotDiscloseSensitiveInformation() { | ||
//Context: https://github.com/appsmithorg/appsmith/issues/21568 | ||
final DuplicateKeyException exception = assertThrows( | ||
DuplicateKeyException.class, | ||
() -> generateDuplicateKeyException()); | ||
|
||
AppsmithError appsmithError = AppsmithError.DUPLICATE_KEY; | ||
assertEquals(appsmithError.getMessage("\\\"MyJSObject\\\""), appsmithError.getMessage(DuplicateKeyExceptionUtils.extractConflictingObjectName(exception.getMessage()))); | ||
} | ||
|
||
private void generateDuplicateKeyException() { | ||
String originalErrorMessage = "Write operation error on server localhost:27017. Write error: WriteError{code=11000, message='E11000 duplicate key error collection: appsmith.actionCollection index: unpublishedCollection.name_1 dup key: { unpublishedCollection.name: \\\"MyJSObject\\\" }', details={}}."; | ||
throw new DuplicateKeyException(originalErrorMessage); | ||
} | ||
} |