File indexing completed on 2025-02-02 04:47:49
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Daniel Weigl <DanielWeigl@gmx.at> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 package org.kde.kdeconnect.Helpers; 0008 0009 public class SafeTextChecker { 0010 0011 private final String safeChars; 0012 private final Integer maxLength; 0013 0014 public SafeTextChecker(String safeChars, Integer maxLength) { 0015 this.safeChars = safeChars; 0016 this.maxLength = maxLength; 0017 } 0018 0019 0020 // is used by the SendKeystrokes functionality to evaluate if a to-be-send text is safe for 0021 // sending without user confirmation 0022 // only allow sending text that can not harm any connected desktop (like "format c:\n" / "rm -rf\n",...) 0023 public boolean isSafe(String content) { 0024 if (content == null) { 0025 return false; 0026 } 0027 0028 if (content.length() > maxLength) { 0029 return false; 0030 } 0031 0032 for (int i = 0; i < content.length(); i++) { 0033 String charAtPos = content.substring(i, i + 1); 0034 if (!safeChars.contains(charAtPos)) { 0035 return false; 0036 } 0037 } 0038 0039 // we are happy with the string 0040 return true; 0041 } 0042 }