-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5adc9c4
commit 7ebb712
Showing
16 changed files
with
546 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,3 +221,4 @@ _meta | |
.serverless | ||
package-lock.json | ||
src/main/resources/lumigo-agent.jar | ||
.vscode/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.lumigo.core.utils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
public class SecretScrubber { | ||
private List<Pattern> scrubbingPatterns; | ||
|
||
private static final String SECRET_PLACEHOLDER = "****"; | ||
|
||
public SecretScrubber(Map<String, String> env) { | ||
this.scrubbingPatterns = new SecretScrubbingPatternProvider(env).getScrubbingPatterns(); | ||
} | ||
|
||
public String scrubStringifiedObject(String stringifiedObject) { | ||
try { | ||
JSONObject jsonObject = new JSONObject(stringifiedObject); | ||
return scrubJsonObject(jsonObject, this.scrubbingPatterns).toString(); | ||
} catch (Exception e) { | ||
return stringifiedObject; | ||
} | ||
} | ||
|
||
private JSONObject scrubJsonObject(JSONObject jsonObject, List<Pattern> patterns) { | ||
for (String key : jsonObject.keySet()) { | ||
Object value = jsonObject.get(key); | ||
|
||
if (value instanceof String && isSecret(key, patterns)) { | ||
jsonObject.put(key, SECRET_PLACEHOLDER); | ||
} else if (value instanceof JSONArray) { | ||
ArrayList<Object> scrubbedArray = new ArrayList<>(); | ||
|
||
for (Object item : (JSONArray) value) { | ||
if (item instanceof String && isSecret(key, patterns)) { | ||
scrubbedArray.add(SECRET_PLACEHOLDER); | ||
} else if (item instanceof JSONObject) { | ||
scrubbedArray.add(scrubJsonObject((JSONObject) item, patterns)); | ||
} else { | ||
scrubbedArray.add(item); | ||
} | ||
} | ||
|
||
jsonObject.put(key, scrubbedArray.toArray()); | ||
|
||
} else if (value instanceof JSONObject) { | ||
jsonObject.put(key, scrubJsonObject((JSONObject) value, patterns)); | ||
} | ||
} | ||
|
||
return jsonObject; | ||
} | ||
|
||
private boolean isSecret(String value, List<Pattern> patterns) { | ||
for (Pattern pattern : patterns) { | ||
if (pattern.matcher(value).matches()) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
Oops, something went wrong.