Skip to content

Commit 5ddb193

Browse files
committed
Do not serialize passwords
1 parent 980dc32 commit 5ddb193

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed

shiny/input_handler.py

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
from __future__ import annotations
22

3-
__all__ = ("input_handlers",)
4-
53
from datetime import date, datetime, timezone
64
from typing import TYPE_CHECKING, Any, Callable, Dict
75

6+
from .bookmark import serializer_unserializable
7+
88
if TYPE_CHECKING:
99
from .session import Session
1010

1111
from .module import ResolvedId
1212
from .types import ActionButtonValue
1313

14+
__all__ = ("input_handlers",)
15+
1416
InputHandlerType = Callable[[Any, ResolvedId, "Session"], Any]
1517

1618

@@ -91,6 +93,10 @@ def _(value, name, session):
9193
return "mypackage.intify";
9294
}
9395
```
96+
97+
See Also
98+
--------
99+
* :class:`~shiny.session.Inputs`'s `.set_serializer(info: InputSerializerInfo)` method for determining how an object can be serialized for bookmarking.
94100
"""
95101

96102

@@ -150,15 +156,50 @@ def _(value: str, name: ResolvedId, session: Session) -> str:
150156
return value
151157

152158

153-
# TODO: implement when we have bookmarking
154-
# TODO: Barret: Input handler for passwords
155159
@input_handlers.add("shiny.password")
156160
def _(value: str, name: ResolvedId, session: Session) -> str:
161+
# Never bookmark passwords
162+
session.input.set_serializer(name, serializer_unserializable)
163+
157164
return value
158165

159166

160-
# TODO: implement when we have bookmarking
161-
# TODO: Barret: Input handler for file inputs
162167
@input_handlers.add("shiny.file")
163168
def _(value: Any, name: ResolvedId, session: Session) -> Any:
169+
170+
# This function is only used when restoring a Shiny ui.input_file.
171+
# When a file is uploaded the usual way, it takes a different code path and won't
172+
# hit this function.
173+
if value is None:
174+
return None
175+
176+
# TODO: Barret: Input handler for file inputs
177+
178+
# # The data will be a named list of lists; convert to a data frame.
179+
# val <- as.data.frame(lapply(val, unlist), stringsAsFactors = FALSE)
180+
181+
# # `val$datapath` should be a filename without a path, for security reasons.
182+
# if (basename(val$datapath) != val$datapath) {
183+
# stop("Invalid '/' found in file input path.")
184+
# }
185+
186+
# # Prepend the persistent dir
187+
# oldfile <- file.path(getCurrentRestoreContext()$dir, val$datapath)
188+
189+
# # Copy the original file to a new temp dir, so that a restored session can't
190+
# # modify the original.
191+
# newdir <- file.path(tempdir(), createUniqueId(12))
192+
# dir.create(newdir)
193+
# val$datapath <- file.path(newdir, val$datapath)
194+
# file.copy(oldfile, val$datapath)
195+
196+
# # Need to mark this input value with the correct serializer. When a file is
197+
# # uploaded the usual way (instead of being restored), this occurs in
198+
# # session$`@uploadEnd`.
199+
# setSerializer(name, serializerFileInput)
200+
201+
# snapshotPreprocessInput(name, snapshotPreprocessorFileInput)
202+
203+
# val
204+
164205
return value

0 commit comments

Comments
 (0)