mirror of
https://github.com/RoboSats/robosats.git
synced 2025-08-15 01:17:15 +00:00
Merge pull request #2155 from aftermath2/fix_regex_format
Escape characters using two backslashes
This commit is contained in:
@ -41,10 +41,7 @@ class WebAppInterface(private val context: MainActivity, private val webView: We
|
|||||||
|
|
||||||
// Security patterns for input validation
|
// Security patterns for input validation
|
||||||
private val UUID_PATTERN = Pattern.compile("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", Pattern.CASE_INSENSITIVE)
|
private val UUID_PATTERN = Pattern.compile("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", Pattern.CASE_INSENSITIVE)
|
||||||
private val SAFE_STRING_PATTERN = Pattern.compile("^[a-zA-Z0-9\s_\-.,:;!?()\[\]{}\"]*$")
|
private val SAFE_STRING_PATTERN = Pattern.compile("^[a-zA-Z0-9\\s_\\-.,:;!?()\\[\\]{}\"]*$")
|
||||||
|
|
||||||
// Maximum length for input strings
|
|
||||||
private val MAX_INPUT_LENGTH = 1000
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// Check if libraries are loaded and show a toast notification if there's an issue
|
// Check if libraries are loaded and show a toast notification if there's an issue
|
||||||
@ -108,6 +105,13 @@ class WebAppInterface(private val context: MainActivity, private val webView: We
|
|||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
fun copyToClipboard(message: String) {
|
fun copyToClipboard(message: String) {
|
||||||
|
// Validate input
|
||||||
|
if (!isValidInput(message)) {
|
||||||
|
Log.e(TAG, "Invalid input for copyToClipboard")
|
||||||
|
Toast.makeText(context, "Invalid content for clipboard", Toast.LENGTH_SHORT).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Copy to clipboard
|
// Copy to clipboard
|
||||||
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager
|
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager
|
||||||
@ -441,8 +445,8 @@ class WebAppInterface(private val context: MainActivity, private val webView: We
|
|||||||
safeEvaluateJavascript("javascript:window.AndroidRobosats.onRejectPromise('$uuid', '$encodedError')")
|
safeEvaluateJavascript("javascript:window.AndroidRobosats.onRejectPromise('$uuid', '$encodedError')")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isValidInput(input: String?, maxLength: Int = MAX_INPUT_LENGTH): Boolean {
|
private fun isValidInput(input: String?): Boolean {
|
||||||
if (input == null || input.isEmpty() || input.length > maxLength) {
|
if (input == null || input.isEmpty()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return SAFE_STRING_PATTERN.matcher(input).matches()
|
return SAFE_STRING_PATTERN.matcher(input).matches()
|
||||||
|
Reference in New Issue
Block a user