Skip to content

Commit d20cc20

Browse files
committed
Added char checking for input fields
1 parent f2a6f3d commit d20cc20

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

backend/onyx/connectors/paperless_ngx/connector.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ def __init__(
7979
# TODO: implement UI changes for the above in web\src\lib\connectors\connectors.tsx?
8080
) -> None:
8181

82+
# test for invalid characters in ingest_tags
83+
if ingest_tags and not all(
84+
char.isalnum() or char in ", " for char in ingest_tags
85+
):
86+
raise ConnectorValidationError(
87+
"Invalid characters in ingest_tags. Only alphanumeric characters, commas, and spaces are allowed."
88+
)
89+
# convert ingest_tags to list of tags
8290
try:
8391
self.ingest_tags: List[str] = (
8492
[tag.strip() for tag in ingest_tags.split(",")] if ingest_tags else []
@@ -88,6 +96,14 @@ def __init__(
8896
f"Could not parse ingest_tags: {ingest_tags}. Error: {e}"
8997
)
9098

99+
# test for invalid characters in ingest_usernames
100+
if ingest_usernames and not all(
101+
char.isalnum() or char in ", " for char in ingest_usernames
102+
):
103+
raise ConnectorValidationError(
104+
"Invalid characters in ingest_usernames. Only alphanumeric characters, commas, and spaces are allowed."
105+
)
106+
# convert ingest_usernames to list of usernames
91107
try:
92108
self.ingest_usernames: List[str] = (
93109
[username.strip() for username in ingest_usernames.split(",")]
@@ -101,16 +117,18 @@ def __init__(
101117

102118
self.ingest_noowner = ingest_noowner
103119

104-
# Allowed ui_min_start_date formats:
105120
# TODO: write code to allow for date-time?
106-
# - yyyy-mm-dd
107-
# - mm/dd/yyyy
108-
# - dd/mm/yyyy
109-
# - mm-dd-yyyy
110-
# - dd-mm-yyyy
111-
# - yyyy/mm/dd
112-
# - dd.mm.yyyy
113-
# - mm.dd.yyyy
121+
"""
122+
Allowed ui_min_start_date formats:
123+
- yyyy-mm-dd
124+
- mm/dd/yyyy
125+
- dd/mm/yyyy
126+
- mm-dd-yyyy
127+
- dd-mm-yyyy
128+
- yyyy/mm/dd
129+
- dd.mm.yyyy
130+
- mm.dd.yyyy
131+
"""
114132
self.master_start_date: Optional[str] = None
115133
if ui_min_start_date:
116134
try:
@@ -163,7 +181,7 @@ def load_credentials(self, credentials: Dict[str, Any]) -> None:
163181
self.auth_token = credentials["paperless_ngx_auth_token"]
164182

165183
if not self.api_url:
166-
raise PermissionError("Paperless-ngx API URL not found in settings.")
184+
raise PermissionError("Paperless-ngx API URL not found in settings.")
167185

168186
if not self.auth_token:
169187
raise PermissionError("Paperless-ngx auth token not found in settings.")

0 commit comments

Comments
 (0)