Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix(SKY-12143): recover credential inputs corrupted by the fill+type caret race (rotation + truncation) (#7570)
LawyZheng905d84620781
diff --git a/skyvern/exceptions.py b/skyvern/exceptions.pyindex 8613ac02c..1f461ab7c 100644--- a/skyvern/exceptions.py+++ b/skyvern/exceptions.py@@ -239,6 +239,12 @@ class RepeatedActionFailure(SkyvernException):)+class SecretInputMismatch(SkyvernException):+ def __init__(self) -> None:+ # No secret material in the message: not the value, its length, or its character classes.+ super().__init__("Secret input read-back mismatch after atomic re-entry.")++class ConditionalBranchEvaluationError(SkyvernException):"""A conditional block could not resolve which branch to take."""diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.pyindex 5c98ef214..1af80a231 100644--- a/skyvern/webeye/actions/handler.py+++ b/skyvern/webeye/actions/handler.py@@ -68,6 +68,7 @@ from skyvern.exceptions import (NoTOTPSecretFound,OptionIndexOutOfBound,PhoneNumberInputMismatch,+ SecretInputMismatch,SkyvernException,)from skyvern.experimentation.wait_utils import get_or_create_wait_config, get_wait_time@@ -2087,6 +2088,113 @@ async def _verify_masked_input_after_fill()+# Native input types whose DOM .value round-trips typed text exactly, so an exact read-back is meaningful.+# password/text/email/search/url and an untyped input default to a text field; tel/number/date-like inputs+# normalize or auto-format their value and are excluded, as are textarea/contenteditable/select (non-input+# sinks whose read-back is trimmed).+_EXACT_VALUE_INPUT_TYPES = frozenset({"password", "text", "email", "search", "url", ""})+# Mask glyphs a reveal/obfuscation widget may render into a non-password .value, optionally grouped by+# these separators (e.g. "•••• ••••" / "****-****").+_SECRET_MASK_CHARS = frozenset("•●·*∗*")+_SECRET_MASK_SEPARATORS = re.compile(r"[\s\-./]")+++def _exact_value_input_type(input_type: str | None) -> str:+ return (input_type or "").strip().lower()+++def _secret_readback_is_unreadable_mask(actual_value: str | None, *, is_password: bool) -> bool:+ # Unreadable only when the read-back is ENTIRELY mask glyphs (optionally separator-grouped, e.g.+ # "•••• ••••" / "****-****"): a custom reveal/mask widget is rendering only bullets, not the real+ # .value, so it cannot be compared and the field is left as typed. A value with any real character is+ # readable and compared exactly -- a revealed secret that merely contains a "*"/"•" must NOT be skipped+ # (that would silently defeat the fix for exactly the "show password" text fields this covers). Callers+ # check exact equality first, so a legitimately all-glyph secret that round-trips is a match, not a+ # skip. A native password input's .value is always the real typed value (mask is visual only).+ if is_password or not actual_value:+ return False+ stripped = _SECRET_MASK_SEPARATORS.sub("", actual_value)+ return bool(stripped) and all(char in _SECRET_MASK_CHARS for char in stripped)+++def _secret_input_cannot_round_trip(text: str, *, maxlength: str | None) -> bool:+ # Some fields cannot hold the intended value exactly by their declared browser contract: a single-line+ # input strips CR/LF, and a positive maxlength shorter than the value truncates it. A read-back would+ # never equal the intended value there, so skip the exact-readback recovery rather than false-failing+ # an as-correct-as-possible fill.+ if "\r" in text or "\n" in text:+ return True+ if maxlength:+ try:+ limit = int(maxlength)+ except ValueError:+ return False+ return 0 <= limit < len(text)+ return False+++def _secret_readback_is_mismatch(expected: str, actual_value: str | None) -> bool:+ # A confirmed rendered value that differs from the intended secret, INCLUDING an empty read-back (the+ # fill was rejected/async-cleared): an empty credential field must be re-entered atomically rather than+ # left as a silent empty submit (SKY-12143). Masked/unreadable and can't-round-trip values are filtered+ # out by the caller before this comparison.+ return actual_value != expected+++def _secret_readback_matches(expected: str, actual_value: str | None) -> bool:+ # Positive confirmation after clearing a known-bad value: only an exact, non-empty readable match is+ # success. An empty or still-mismatched retry read-back forces a loud failure over an unverified secret.+ return bool(actual_value) and actual_value == expected+++async def _fill_secret_with_readback(+ *, skyvern_element: SkyvernElement, tag_name: str, text: str, input_type: str, maxlength: str | None+) -> ActionFailure | None:+ # Character-by-character credential entry can race a hardened field's caret restore and rotate the+ # value, or be dropped by a controlled field and truncate it, while the block still completes --+ # submitting a wrong/empty credential with no visible error (SKY-12143 rotation; SKY-12597/12579+ # truncation; same family as the card-number read-back, SKY-11720). On the native exact-value inputs+ # this runs for, read the value back and, on an empty or mismatched read-back, re-enter atomically (a+ # single value-set has no per-keystroke race) and positively confirm. Fields that cannot round-trip the+ # value by their declared contract, or whose .value renders only mask glyphs, are left as typed. Logs+ # carry only the element id, never the secret, its length, or its character classes.+ is_password = input_type == "password"++ await skyvern_element.input_sequentially(text=text)++ if _secret_input_cannot_round_trip(text, maxlength=maxlength):+ LOG.info(+ "Leaving credential as typed: field cannot round-trip the value by its declared contract",+ element_id=skyvern_element.get_id(),+ )+ return None++ actual_value = await get_input_value(tag_name=tag_name, locator=skyvern_element.get_locator())+ # Exact equality first: a value that round-trips exactly is confirmed, even one made only of mask-like+ # characters -- so an all-"*" secret is a match, never misclassified as an unreadable mask.+ if not _secret_readback_is_mismatch(text, actual_value):+ return None++ if _secret_readback_is_unreadable_mask(actual_value, is_password=is_password):+ LOG.info(+ "Leaving credential as typed: rendered value is masked and cannot be verified",+ element_id=skyvern_element.get_id(),+ )+ return None++ await skyvern_element.input_clear()+ await skyvern_element.input_fill(text=text)+ actual_value = await get_input_value(tag_name=tag_name, locator=skyvern_element.get_locator())+ if _secret_readback_matches(text, actual_value):+ return None++ LOG.warning(+ "Secret input read-back mismatch after retry",+ element_id=skyvern_element.get_id(),+ )+ return ActionFailure(SecretInputMismatch())++def _select_option_target_value(option: SelectOption) -> str | None:if option.label:return option.label@@ -4345,11 +4453,32 @@ async def handle_input_text_action(if is_card_number_input:card_expected_digits = candidate_card_digits+ # SKY-12143 / SKY-12597 / SKY-12579: character-by-character credential entry can race a hardened+ # field's caret restore (rotating the value) or be dropped by a controlled field (truncating it),+ # submitting a wrong or empty credential while the block still completes. On native inputs whose DOM+ # .value round-trips typed text exactly, read the value back and re-enter atomically on an empty or+ # mismatched read-back, compared character-for-character. Scoped to non-TOTP secrets on exact-value+ # input types (password/text/email/search/url/untyped); tel and card keep their digit-normalized+ # paths above, and number/date/textarea/contenteditable/select cannot round-trip exactly so they are+ # excluded. Evaluated on the actual element being filled, which find_blocking_element may have+ # retargeted above. A single character cannot be order-scrambled, so it is skipped.+ secret_input_type = _exact_value_input_type(await skyvern_element.get_attr("type"))+ verify_secret_input = (+ is_secret_value+ and not is_totp_value+ and len(text) > 1+ and not is_card_number_input+ and tag_name == InteractiveElement.INPUT+ and secret_input_type in _EXACT_VALUE_INPUT_TYPES+ )+ secret_maxlength = await skyvern_element.get_attr("maxlength") if verify_secret_input else None+# Masked inputs (postal code, SSN) can report a successful fill while the mask committed nothing.- # Read the value back for masked fields and, on an empty/placeholder commit, retype once.+ # Read the value back for masked fields and, on an empty/placeholder commit, retype once. Scoped to+ # non-credential fields: a credential value is handled by the exact secret read-back above.verify_masked_input_after_fill = Falsemask_attr_evidence = False- if not is_tel and await _is_masked_input_readback_fix_enabled(task):+ if not is_tel and not verify_secret_input and await _is_masked_input_readback_fix_enabled(task):mask_attr_evidence = _has_input_mask_evidence(pattern=await skyvern_element.get_attr("pattern"),placeholder=await skyvern_element.get_attr("placeholder"),@@ -4357,7 +4486,12 @@ async def handle_input_text_action(verify_masked_input_after_fill = Truegeneric_commit_input_type = None- if not is_tel and not card_expected_digits and await _is_input_text_commit_verification_enabled(task):+ if (+ not is_tel+ and not card_expected_digits+ and not verify_secret_input+ and await _is_input_text_commit_verification_enabled(task)+ ):generic_commit_input_type = _is_generic_input_commit_candidate(tag_name=tag_name,live_input_type=live_input_type,@@ -4366,6 +4500,7 @@ async def handle_input_text_action(input_context_destroyed = Falsetry:+ # Read-back/recover priority: card > tel > secret > masked > plain fill (each gate is mutually exclusive).if card_expected_digits:card_failure = await _fill_card_number_with_readback(skyvern_element=skyvern_element,@@ -4390,6 +4525,16 @@ async def handle_input_text_action(actual_digit_count=phone_mismatch.actual_digit_count,)return [ActionFailure(phone_mismatch)]+ elif verify_secret_input:+ secret_failure = await _fill_secret_with_readback(+ skyvern_element=skyvern_element,+ tag_name=tag_name,+ text=text,+ input_type=secret_input_type,+ maxlength=secret_maxlength,+ )+ if secret_failure is not None:+ return [secret_failure]elif verify_masked_input_after_fill:await skyvern_element.input_sequentially(text=text)# Read the committed value back; on an empty/placeholder commit, refocus, clear and retypediff --git a/tests/unit/test_input_secret_readback.py b/tests/unit/test_input_secret_readback.pynew file mode 100644index 000000000..188682a4d--- /dev/null+++ b/tests/unit/test_input_secret_readback.py@@ -0,0 +1,354 @@+from __future__ import annotations++from unittest.mock import AsyncMock, MagicMock, patch++import pytest++from skyvern.webeye.actions.handler import (+ _exact_value_input_type,+ _fill_secret_with_readback,+ _secret_input_cannot_round_trip,+ _secret_readback_is_mismatch,+ _secret_readback_is_unreadable_mask,+ _secret_readback_matches,+)+from skyvern.webeye.actions.responses import ActionFailure++# Synthetic secret, not a real credential. It is longer than the fill+type split threshold so the entry+# exercises the fill(prefix) + type(tail) seam where the caret race rotates the value.+SECRET = "abcdefghijklmno"+# The fill+type caret race on a hardened field rotates the value by the filled-prefix length (len - 10).+ROTATED = SECRET[5:] + SECRET[:5]+# A controlled field can drop the typed tail, truncating the value.+TRUNCATED = SECRET[:-3]+# The shortest value the gate still verifies (a single character cannot be order-scrambled).+SHORT_SECRET = "ab"+# A secret that legitimately contains mask-like characters; a password input's .value returns them as-is.+GLYPH_SECRET = "ab*c•de"+GLYPH_SCRAMBLED = GLYPH_SECRET[3:] + GLYPH_SECRET[:3]+++ "actual_value,is_mismatch",+ [+ (SECRET, False), # correct value -> not a mismatch+ (ROTATED, True), # rotated value, same length -> mismatch+ (TRUNCATED, True), # dropped tail -> mismatch+ (SECRET[:-1], True), # dropped character -> mismatch+ ("", True), # empty read-back -> mismatch, must be re-entered atomically+ (None, True), # unreadable read-back -> mismatch+ ],+)+def test_secret_readback_is_mismatch(actual_value: str | None, is_mismatch: bool) -> None:+ assert _secret_readback_is_mismatch(SECRET, actual_value) is is_mismatch+++ "actual_value,matches",+ [+ (SECRET, True), # exact match+ (ROTATED, False), # rotated -> not a positive match+ (SECRET[:-1], False), # dropped character -> not a positive match+ ("", False), # empty -> not a positive match+ (None, False), # unreadable -> not a positive match+ ],+)+def test_secret_readback_matches(actual_value: str | None, matches: bool) -> None:+ assert _secret_readback_matches(SECRET, actual_value) is matches+++ "actual_value,is_masked",+ [+ ("••••••••", True), # entirely bullets -> unreadable+ ("•••• ••••", True), # bullets grouped by a space separator -> unreadable+ ("****-****", True), # entirely asterisks with a hyphen separator -> unreadable+ ("*", True), # a single mask glyph and nothing else -> unreadable+ ("ab•cde", False), # a real value that merely contains one glyph -> readable (compared exactly)+ ("p*ssw0rd", False), # a revealed password containing "*" -> readable, must NOT be skipped+ ("mysecretvalue", False), # a real rendered value -> readable+ ("", False), # empty is not "masked" -> handled as a mismatch, not a skip+ (None, False), # unreadable/None -> handled as a mismatch, not a skip+ ],+)+def test_secret_readback_is_unreadable_mask_non_password(actual_value: str | None, is_masked: bool) -> None:+ assert _secret_readback_is_unreadable_mask(actual_value, is_password=False) is is_masked+++def test_password_readback_is_never_masked() -> None:+ # A native password input's .value is the real typed value, so mask-like glyphs are real characters+ # and the value is always comparable -- never treated as an unreadable mask.+ assert _secret_readback_is_unreadable_mask("••••••••", is_password=True) is False+ assert _secret_readback_is_unreadable_mask(GLYPH_SECRET, is_password=True) is False+++ "text,maxlength,cannot_round_trip",+ [+ (SECRET, None, False), # no declared constraint -> round-trips+ (SECRET, "20", False), # maxlength longer than the value -> round-trips+ (SECRET, "8", True), # positive maxlength shorter than the value -> truncates+ (SECRET, "0", True), # maxlength 0 cannot hold a >1 char value+ (SECRET, "abc", False), # unparseable maxlength -> ignore, do not skip+ (SECRET, "", False), # empty maxlength attr -> ignore, do not skip+ ("abc\ndef", None, True), # a single-line input strips LF -> cannot round-trip+ ("abc\r\ndef", None, True), # CRLF stripped -> cannot round-trip+ ],+)+def test_secret_input_cannot_round_trip(text: str, maxlength: str | None, cannot_round_trip: bool) -> None:+ assert _secret_input_cannot_round_trip(text, maxlength=maxlength) is cannot_round_trip+++ "input_type,normalized",+ [+ ("password", "password"),+ ("TEXT", "text"),+ (" email ", "email"),+ (None, ""),+ ("", ""),+ ],+)+def test_exact_value_input_type_normalizes(input_type: str | None, normalized: str) -> None:+ assert _exact_value_input_type(input_type) == normalized+++def _make_secret_element(readbacks: list[str | None]) -> MagicMock:+ locator = MagicMock()+ locator.input_value = AsyncMock(side_effect=list(readbacks))+ element = MagicMock()+ element.get_locator = MagicMock(return_value=locator)+ element.get_id = MagicMock(return_value="secret")+ element.input_sequentially = AsyncMock()+ element.input_clear = AsyncMock()+ element.input_fill = AsyncMock()+ return element+++async def _fill(+ element: MagicMock, *, text: str = SECRET, input_type: str = "password", maxlength: str | None = None+) -> ActionFailure | None:+ return await _fill_secret_with_readback(+ skyvern_element=element, tag_name="input", text=text, input_type=input_type, maxlength=maxlength+ )+++async def test_fill_secret_recovers_rotation_with_atomic_fill() -> None:+ # First (character-by-character) entry rotates the value; the atomic re-entry renders it exactly.+ element = _make_secret_element([ROTATED, SECRET])++ result = await _fill(element)++ assert result is None+ element.input_sequentially.assert_awaited_once_with(text=SECRET)+ element.input_clear.assert_awaited_once()+ element.input_fill.assert_awaited_once_with(text=SECRET)+++async def test_fill_secret_recovers_text_truncation_via_readback() -> None:+ # SKY-12597/12579: a controlled text/email field drops the typed tail; the atomic re-fill recovers it.+ element = _make_secret_element([TRUNCATED, SECRET])++ result = await _fill(element, input_type="text")++ assert result is None+ element.input_clear.assert_awaited_once()+ element.input_fill.assert_awaited_once_with(text=SECRET)+++async def test_fill_secret_recovers_scramble_containing_mask_glyph_on_password() -> None:+ # A password secret containing "*"/"•" scrambled is caught by the exact .value comparison and recovered+ # by the atomic re-entry -- not skipped as "masked" (a password .value is the real value).+ element = _make_secret_element([GLYPH_SCRAMBLED, GLYPH_SECRET])++ result = await _fill(element, text=GLYPH_SECRET, input_type="password")++ assert result is None+ element.input_clear.assert_awaited_once()+ element.input_fill.assert_awaited_once_with(text=GLYPH_SECRET)+++async def test_fill_secret_clean_first_try_skips_retry() -> None:+ element = _make_secret_element([SECRET])++ result = await _fill(element)++ assert result is None+ element.input_clear.assert_not_awaited()+ element.input_fill.assert_not_awaited()++[email protected]("text", [SECRET, SHORT_SECRET])+async def test_fill_secret_recovers_drop_to_empty(text: str) -> None:+ # An empty first read-back (the fill was rejected/dropped) triggers the atomic recovery for both a long+ # and a short credential rather than silently submitting an empty field.+ element = _make_secret_element(["", text])++ result = await _fill(element, text=text, input_type="text")++ assert result is None+ element.input_clear.assert_awaited_once()+ element.input_fill.assert_awaited_once_with(text=text)+++async def test_fill_secret_fails_after_second_mismatch() -> None:+ element = _make_secret_element([ROTATED, ROTATED])++ result = await _fill(element)++ assert isinstance(result, ActionFailure)+ assert result.success is False+ assert result.exception_type == "SecretInputMismatch"+ element.input_fill.assert_awaited_once_with(text=SECRET)+++async def test_fill_secret_fails_when_retry_readback_empty() -> None:+ # After a confirmed first mismatch we cleared a known-bad value; an empty retry read-back is NOT a+ # positive confirmation, so fail loudly rather than proceed with an unverified secret.+ element = _make_secret_element([ROTATED, ""])++ result = await _fill(element)++ assert isinstance(result, ActionFailure)+ assert result.exception_type == "SecretInputMismatch"+ element.input_fill.assert_awaited_once_with(text=SECRET)++[email protected]("text", [SECRET, SHORT_SECRET])+async def test_fill_secret_fails_when_persistently_empty(text: str) -> None:+ element = _make_secret_element(["", ""])++ result = await _fill(element, text=text, input_type="text")++ assert isinstance(result, ActionFailure)+ assert result.exception_type == "SecretInputMismatch"+ element.input_fill.assert_awaited_once_with(text=text)+++async def test_fill_secret_transforming_field_loud_fails() -> None:+ # An eligible text field that transforms the value (e.g. uppercases it) with no declared incompatibility+ # still mismatches after the atomic re-fill -> loud failure rather than submitting a known-different+ # credential (account-lockout-safe over silent-wrong-submit).+ transformed = SECRET.upper()+ element = _make_secret_element([transformed, transformed])++ result = await _fill(element, input_type="text")++ assert isinstance(result, ActionFailure)+ assert result.exception_type == "SecretInputMismatch"+++async def test_fill_secret_skips_fully_masked_non_password_field() -> None:+ # A non-password field that renders ONLY mask glyphs into .value for a real (non-glyph) secret cannot be+ # verified; leave it as typed rather than clearing a possibly-correct value and false-failing.+ element = _make_secret_element(["••••••••••••••••"])++ result = await _fill(element, input_type="text")++ assert result is None+ element.input_sequentially.assert_awaited_once_with(text=SECRET)+ element.input_clear.assert_not_awaited()+ element.input_fill.assert_not_awaited()+++# A revealed (type=text) secret that contains mask-like characters mixed with real ones.+MIXED_MASK_SECRET = "aB*cd•eF*gh"+MIXED_MASK_SCRAMBLED = MIXED_MASK_SECRET[4:] + MIXED_MASK_SECRET[:4]+++async def test_fill_secret_recovers_mixed_mask_secret_on_text_field() -> None:+ # The any()->all() correctness fix: a revealed secret containing a "*"/"•" among real characters is+ # readable, so a scramble is a real mismatch that gets recovered -- it must NOT be skipped as masked+ # (which would silently reproduce the bug for exactly the "show password" text fields this covers).+ element = _make_secret_element([MIXED_MASK_SCRAMBLED, MIXED_MASK_SECRET])++ result = await _fill(element, text=MIXED_MASK_SECRET, input_type="text")++ assert result is None+ element.input_clear.assert_awaited_once()+ element.input_fill.assert_awaited_once_with(text=MIXED_MASK_SECRET)+++async def test_fill_secret_mixed_mask_secret_exact_match_needs_no_recovery() -> None:+ element = _make_secret_element([MIXED_MASK_SECRET])++ result = await _fill(element, text=MIXED_MASK_SECRET, input_type="text")++ assert result is None+ element.input_clear.assert_not_awaited()+ element.input_fill.assert_not_awaited()+++async def test_fill_secret_all_glyph_secret_exact_match_is_not_skipped() -> None:+ # A secret that is legitimately all mask glyphs and round-trips exactly is a MATCH (confirmed), not an+ # unreadable-mask skip -- equality is checked before the mask heuristic.+ all_glyph = "******"+ element = _make_secret_element([all_glyph])++ result = await _fill(element, text=all_glyph, input_type="text")++ assert result is None+ element.input_clear.assert_not_awaited()+ element.input_fill.assert_not_awaited()+++async def test_fill_secret_skips_maxlength_truncating_field_without_reading_back() -> None:+ # A field whose positive maxlength is shorter than the value cannot hold it; skip the exact read-back+ # (no read, no clear, no fail) so a legacy truncate-at-signup-and-login site keeps succeeding.+ element = _make_secret_element([])++ result = await _fill(element, input_type="text", maxlength="8")++ assert result is None+ element.input_sequentially.assert_awaited_once_with(text=SECRET)+ element.get_locator.return_value.input_value.assert_not_awaited()+ element.input_clear.assert_not_awaited()+ element.input_fill.assert_not_awaited()+++async def test_fill_secret_skips_newline_bearing_single_line_field() -> None:+ # A single-line input strips CR/LF, so a stored secret containing a newline can never round-trip;+ # skip the read-back instead of deterministically loud-failing a correct-as-possible fill.+ text = "abcdefghij\nklmnop"+ element = _make_secret_element([])++ result = await _fill(element, text=text, input_type="text")++ assert result is None+ element.input_sequentially.assert_awaited_once_with(text=text)+ element.get_locator.return_value.input_value.assert_not_awaited()+ element.input_clear.assert_not_awaited()+++async def test_fill_secret_logs_carry_no_secret_material() -> None:+ # The loud-failure path must never log the secret, its length, or its character classes.+ element = _make_secret_element([ROTATED, ROTATED])++ with patch("skyvern.webeye.actions.handler.LOG") as mock_log:+ result = await _fill(element)++ assert isinstance(result, ActionFailure)+ logged = " ".join(+ repr(call.args) + repr(call.kwargs) for call in (*mock_log.warning.mock_calls, *mock_log.info.mock_calls)+ )+ assert SECRET not in logged+ assert ROTATED not in logged+ assert str(len(SECRET)) not in logged+ assert result.exception_type == "SecretInputMismatch"+ assert SECRET not in (result.exception_message or "")diff --git a/tests/unit/test_input_text_tel_card_routing.py b/tests/unit/test_input_text_tel_card_routing.pyindex 802dd56b6..caaf70622 100644--- a/tests/unit/test_input_text_tel_card_routing.py+++ b/tests/unit/test_input_text_tel_card_routing.py@@ -7,6 +7,7 @@ import pytestfrom skyvern.exceptions import PhoneNumberInputMismatchfrom skyvern.forge.sdk.models import StepStatus+from skyvern.forge.sdk.services.bitwarden import BitwardenConstantsfrom skyvern.webeye.actions.actions import InputTextActionfrom skyvern.webeye.actions.handler import handle_input_text_actionfrom skyvern.webeye.actions.responses import ActionFailure, ActionSuccess@@ -51,13 +52,19 @@ async def _run_input_text(el: MagicMock,text: str,*,+ resolved: str | None = None,tel_fix_enabled: bool = True,tel_verify_side_effect: list[Exception | None] | None = None,generic_flag: bool = True,incremental_elements: list[dict] | None = None,-) -> tuple[list, AsyncMock, AsyncMock, AsyncMock, MagicMock, AsyncMock]:+ tag_name: str = "input",+ blocker: MagicMock | None = None,+) -> tuple[list, AsyncMock, AsyncMock, AsyncMock, MagicMock, AsyncMock, AsyncMock]:dom_instance = MagicMock()dom_instance.get_skyvern_element_by_id = AsyncMock(return_value=el)+ if blocker is not None:+ # find_blocking_element() retargets the fill from `el` to this editable blocker.+ el.find_blocking_element = AsyncMock(return_value=(blocker, True))inc = MagicMock()inc.start_listen_dom_increment = AsyncMock()@@ -68,20 +75,26 @@ async def _run_input_text(skyvern_frame.safe_wait_for_animation_end = AsyncMock()scraped_page = MagicMock()- scraped_page.id_to_element_dict = {"AADC": {"tagName": "input"}}+ scraped_page.id_to_element_dict = {"AADC": {"tagName": tag_name}}card_readback = AsyncMock(return_value=None)tel_verify = AsyncMock(side_effect=tel_verify_side_effect)generic_verify = AsyncMock(return_value=None)phone_format = AsyncMock(return_value=text)warning_log = MagicMock()+ secret_readback = AsyncMock(return_value=None)+ # A resolved secret differs from the action's placeholder text; when equal, the value is not a secret.+ secret_return = text if resolved is None else resolvedwith (patch("skyvern.webeye.actions.handler.DomUtil", return_value=dom_instance),patch("skyvern.webeye.actions.handler.SkyvernFrame.create_instance", new=AsyncMock(return_value=skyvern_frame)),patch("skyvern.webeye.actions.handler.IncrementalScrapePage", return_value=inc),patch("skyvern.webeye.actions.handler.get_input_value", new=AsyncMock(return_value="")),- patch("skyvern.webeye.actions.handler.get_actual_value_of_parameter_if_secret_with_task", return_value=text),+ patch(+ "skyvern.webeye.actions.handler.get_actual_value_of_parameter_if_secret_with_task",+ return_value=secret_return,+ ),patch("skyvern.webeye.actions.handler._get_input_or_select_context", new=AsyncMock(return_value=None)),patch("skyvern.webeye.actions.handler._is_tel_digit_fix_enabled", new=AsyncMock(return_value=tel_fix_enabled)),patch(@@ -90,6 +103,7 @@ async def _run_input_text(),patch("skyvern.webeye.actions.handler.check_phone_number_format", new=phone_format),patch("skyvern.webeye.actions.handler._fill_card_number_with_readback", new=card_readback),+ patch("skyvern.webeye.actions.handler._fill_secret_with_readback", new=secret_readback),patch("skyvern.webeye.actions.handler._verify_tel_input_after_fill", new=tel_verify),patch("skyvern.webeye.actions.handler._verify_generic_input_commit", new=generic_verify),patch("skyvern.webeye.actions.handler.check_date_format", new=AsyncMock(return_value=text)),@@ -103,7 +117,7 @@ async def _run_input_text(step=_STEP,)- return results, card_readback, tel_verify, phone_format, warning_log, generic_verify+ return results, card_readback, tel_verify, phone_format, warning_log, generic_verify, secret_readback@pytest.mark.asyncio@@ -117,7 +131,9 @@ async def _run_input_text(async def test_tel_card_number_field_uses_card_readback_not_phone_format(attrs: dict[str, str | None]) -> None:el = _mock_input(attrs)- results, card_readback, tel_verify, phone_format, _, generic_verify = await _run_input_text(el, VISA_16)+ results, card_readback, tel_verify, phone_format, _, generic_verify, secret_readback = await _run_input_text(+ el, VISA_16+ )assert len(results) == 1 and isinstance(results[0], ActionSuccess)card_readback.assert_awaited_once_with(@@ -129,6 +145,7 @@ async def test_tel_card_number_field_uses_card_readback_not_phone_format(attrs:phone_format.assert_not_awaited()tel_verify.assert_not_awaited()generic_verify.assert_not_awaited()+ secret_readback.assert_not_awaited()el.input_sequentially.assert_not_awaited()@@ -136,7 +153,9 @@ async def test_tel_card_number_field_uses_card_readback_not_phone_format(attrs:async def test_ten_digit_tel_phone_uses_tel_readback_not_card_readback() -> None:el = _mock_input({"type": "tel", "autocomplete": None, "name": "phone"})- results, card_readback, tel_verify, phone_format, _, generic_verify = await _run_input_text(el, "224-555-0199")+ results, card_readback, tel_verify, phone_format, _, generic_verify, secret_readback = await _run_input_text(+ el, "224-555-0199"+ )assert len(results) == 1 and isinstance(results[0], ActionSuccess)el.input_sequentially.assert_awaited_once_with(text="2245550199")@@ -149,13 +168,14 @@ async def test_ten_digit_tel_phone_uses_tel_readback_not_card_readback() -> Nonecard_readback.assert_not_awaited()phone_format.assert_not_awaited()generic_verify.assert_not_awaited()+ secret_readback.assert_not_awaited()@pytest.mark.asyncioasync def test_tel_flag_off_preserves_legacy_format_and_sequential_fill() -> None:el = _mock_input({"type": "tel", "autocomplete": None, "name": "phone"})- results, _, tel_verify, phone_format, _, _ = await _run_input_text(+ results, _, tel_verify, phone_format, _, _, _ = await _run_input_text(el,"224-555-0199",tel_fix_enabled=False,@@ -177,7 +197,7 @@ async def test_separator_only_tel_never_forces_nanp_country_code() -> None:PhoneNumberInputMismatch(expected_digit_count=10, actual_digit_count=12),]- results, _, tel_verify, _, warning_log, _ = await _run_input_text(+ results, _, tel_verify, _, warning_log, _, _ = await _run_input_text(el,"224-555-0199",tel_verify_side_effect=mismatches,@@ -205,7 +225,7 @@ async def test_explicit_nanp_tel_keeps_constraint_safe_e164_fallback() -> None:None,]- results, _, tel_verify, _, _, _ = await _run_input_text(+ results, _, tel_verify, _, _, _, _ = await _run_input_text(el,"+1 (224) 555-0199",tel_verify_side_effect=mismatches_then_success,@@ -225,7 +245,7 @@ async def test_explicit_nanp_tel_keeps_constraint_safe_e164_fallback() -> None:async def test_generic_text_input_runs_commit_verification() -> None:el = _mock_input({"type": "text", "autocomplete": None, "name": "postal_code"})- results, card_readback, tel_verify, phone_format, _, generic_verify = await _run_input_text(el, "12345")+ results, card_readback, tel_verify, phone_format, _, generic_verify, _ = await _run_input_text(el, "12345")assert len(results) == 1 and isinstance(results[0], ActionSuccess)el.input_sequentially.assert_awaited_once_with(text="12345")@@ -250,7 +270,7 @@ async def test_blocking_date_input_refreshes_type_before_routing() -> None:blocking.get_id.return_value = "BLOCKING"original.find_blocking_element = AsyncMock(return_value=(blocking, True))- results, _, _, _, _, generic_verify = await _run_input_text(original, "2026-07-17")+ results, _, _, _, _, generic_verify, _ = await _run_input_text(original, "2026-07-17")assert len(results) == 1 and isinstance(results[0], ActionSuccess)blocking.input_fill.assert_awaited_once_with(text="2026-07-17")@@ -262,20 +282,22 @@ async def test_blocking_date_input_refreshes_type_before_routing() -> None:async def test_generic_text_input_skips_commit_verification_when_flag_disabled() -> None:el = _mock_input({"type": "text", "autocomplete": None, "name": "postal_code"})- results, _, _, _, _, generic_verify = await _run_input_text(el, "12345", generic_flag=False)+ results, _, _, _, _, generic_verify, _ = await _run_input_text(el, "12345", generic_flag=False)assert len(results) == 1 and isinstance(results[0], ActionSuccess)el.input_sequentially.assert_awaited_once_with(text="12345")generic_verify.assert_not_awaited()+ # The credential-scope classification and the baseline live_input_type each read the live type,+ # independent of the commit-verification flag; a disabled flag still queries type exactly twice.type_queries = [call for call in el.get_attr.await_args_list if call.args == ("type",)]- assert len(type_queries) == 1+ assert len(type_queries) == 2@pytest.mark.asyncioasync def test_generic_text_input_verifies_after_unrelated_dom_mutation() -> None:el = _mock_input({"type": "text", "autocomplete": None, "name": "postal_code"})- results, _, _, _, _, generic_verify = await _run_input_text(+ results, _, _, _, _, generic_verify, _ = await _run_input_text(el,"12345",incremental_elements=[{"tagName": "div", "attributes": {"class": "field-error"}, "children": []}],@@ -290,7 +312,7 @@ async def test_generic_text_input_verifies_after_unrelated_dom_mutation() -> Nonasync def test_generic_text_input_allows_autocomplete_rewrite_for_option_mutation() -> None:el = _mock_input({"type": "text", "autocomplete": None, "name": "postal_code"})- results, _, _, _, _, generic_verify = await _run_input_text(+ results, _, _, _, _, generic_verify, _ = await _run_input_text(el,"12345",incremental_elements=[@@ -311,7 +333,176 @@ async def test_generic_text_input_allows_autocomplete_rewrite_for_option_mutatioasync def test_password_input_skips_commit_verification() -> None:el = _mock_input({"type": "password", "autocomplete": None, "name": "credential"})- results, _, _, _, _, generic_verify = await _run_input_text(el, "private payload")+ results, _, _, _, _, generic_verify, _ = await _run_input_text(el, "private payload")assert len(results) == 1 and isinstance(results[0], ActionSuccess)generic_verify.assert_not_awaited()+++async def test_secret_tel_value_uses_tel_verifier_not_secret_readback() -> None:+ # A resolved secret that is a NANP phone number must keep the digit-normalized tel verification+ # (a type=tel field renders punctuation), not the exact secret read-back which would false-mismatch+ # the bare digits against the formatted value and fail a correct fill.+ el = _mock_input({"type": "tel", "autocomplete": None, "name": "phone"})++ results, card_readback, tel_verify, phone_format, _, _, secret_readback = await _run_input_text(+ el, "{{ phone }}", resolved="224-555-0199"+ )++ assert len(results) == 1 and isinstance(results[0], ActionSuccess)+ el.input_sequentially.assert_awaited_once_with(text="2245550199")+ tel_verify.assert_awaited_once_with(+ skyvern_element=el,+ tag_name="input",+ expected_value="2245550199",+ allow_nanp_country_prefix=False,+ )+ secret_readback.assert_not_awaited()+ card_readback.assert_not_awaited()+++async def test_single_character_secret_skips_readback() -> None:+ # A one-character secret cannot be order-scrambled, so even a password input skips the read-back+ # (e.g. a multi-field TOTP digit routed into a masked box: is_secret_value True, is_totp_value False).+ el = _mock_input({"type": "password", "autocomplete": None, "name": "otp-digit"})++ results, card_readback, tel_verify, phone_format, _, _, secret_readback = await _run_input_text(+ el, "{{ digit }}", resolved="5"+ )++ assert len(results) == 1 and isinstance(results[0], ActionSuccess)+ el.input_sequentially.assert_awaited_once_with(text="5")+ secret_readback.assert_not_awaited()+ tel_verify.assert_not_awaited()+ card_readback.assert_not_awaited()+++async def test_secret_in_non_input_element_skips_readback() -> None:+ # A contenteditable/div is not a native input (its read-back is trimmed/normalized), so the read-back+ # is skipped; it keeps the plain sequential fill and its pre-existing behavior.+ el = _mock_input({"type": None, "autocomplete": None, "name": "note"})+ el.get_tag_name.return_value = "div"++ results, card_readback, tel_verify, phone_format, _, _, secret_readback = await _run_input_text(+ el, "{{ sec }}", resolved="mysecretvalue", tag_name="div"+ )++ assert len(results) == 1 and isinstance(results[0], ActionSuccess)+ el.input_sequentially.assert_awaited_once_with(text="mysecretvalue")+ secret_readback.assert_not_awaited()++[email protected]("input_type", ["password", "text", "email", "search", "url", None])+async def test_secret_in_exact_value_input_uses_readback(input_type: str | None) -> None:+ # Every native exact-value input type (password/text/email/search/url and an untyped input) round-trips+ # its .value exactly, so the credential read-back verifier runs and is told the live type.+ el = _mock_input({"type": input_type, "autocomplete": None, "name": "credential"})++ results, card_readback, tel_verify, phone_format, _, generic_verify, secret_readback = await _run_input_text(+ el, "{{ sec }}", resolved="mysecretvalue", tag_name="input"+ )++ assert len(results) == 1 and isinstance(results[0], ActionSuccess)+ secret_readback.assert_awaited_once_with(+ skyvern_element=el,+ tag_name="input",+ text="mysecretvalue",+ input_type=input_type or "",+ maxlength=None,+ )+ el.input_sequentially.assert_not_awaited()+ # A credential takes only the exact secret read-back; the generic commit verifier must not also run.+ generic_verify.assert_not_awaited()++[email protected]("input_type", ["number", "datetime-local", "month", "week"])+async def test_secret_in_non_exact_value_input_skips_readback(input_type: str) -> None:+ # number/date-like inputs normalize or reformat their value, so an exact read-back is not meaningful;+ # they keep the plain sequential fill, not the exact read-back. (type=date has its own dedicated fill+ # path earlier and never reaches this gate.)+ el = _mock_input({"type": input_type, "autocomplete": None, "name": "field"})++ results, card_readback, tel_verify, phone_format, _, _, secret_readback = await _run_input_text(+ el, "{{ sec }}", resolved="mysecretvalue", tag_name="input"+ )++ assert len(results) == 1 and isinstance(results[0], ActionSuccess)+ el.input_sequentially.assert_awaited_once_with(text="mysecretvalue")+ secret_readback.assert_not_awaited()+++async def test_secret_readback_skips_when_retargeted_to_out_of_scope_blocker() -> None:+ # find_blocking_element() can retarget the fill to an editable blocker; the credential read-back gate+ # must be re-evaluated on the actual (blocker) element. A number blocker is out of the exact-value+ # scope, so no read-back runs even though the original element was in scope.+ el = _mock_input({"type": "text", "autocomplete": None, "name": "credential"})+ blocker = _mock_input({"type": "number", "autocomplete": None, "name": "overlay"})++ results, card_readback, tel_verify, phone_format, _, _, secret_readback = await _run_input_text(+ el, "{{ sec }}", resolved="mysecretvalue", tag_name="input", blocker=blocker+ )++ assert len(results) == 1 and isinstance(results[0], ActionSuccess)+ blocker.input_sequentially.assert_awaited_once_with(text="mysecretvalue")+ secret_readback.assert_not_awaited()+ el.input_sequentially.assert_not_awaited()+++async def test_secret_readback_runs_on_retargeted_element_type() -> None:+ # The read-back gate reads the live type of the actual (blocker) element: retargeting an in-scope text+ # element to a password blocker still runs the read-back, keyed on the blocker's type.+ el = _mock_input({"type": "text", "autocomplete": None, "name": "overlay"})+ blocker = _mock_input({"type": "password", "autocomplete": None, "name": "password"})++ results, card_readback, tel_verify, phone_format, _, _, secret_readback = await _run_input_text(+ el, "{{ sec }}", resolved="mysecretvalue", tag_name="input", blocker=blocker+ )++ assert len(results) == 1 and isinstance(results[0], ActionSuccess)+ secret_readback.assert_awaited_once_with(+ skyvern_element=blocker,+ tag_name="input",+ text="mysecretvalue",+ input_type="password",+ maxlength=None,+ )+++async def test_non_secret_exact_value_input_skips_readback() -> None:+ # A non-secret value in an exact-value input is not a credential, so the read-back verifier never runs;+ # only secrets are read back.+ el = _mock_input({"type": "text", "autocomplete": None, "name": "search"})++ results, card_readback, tel_verify, phone_format, _, _, secret_readback = await _run_input_text(+ el, "not a secret value"+ )++ assert len(results) == 1 and isinstance(results[0], ActionSuccess)+ el.input_sequentially.assert_awaited_once_with(text="not a secret value")+ secret_readback.assert_not_awaited()+++async def test_totp_value_short_circuits_before_secret_readback() -> None:+ # A resolved TOTP value is recognized as TOTP and short-circuits in the TOTP path before the credential+ # read-back is ever reached (this fixture's task has no valid TOTP secret, so it fails closed with+ # NoTOTPSecretFound -- whatever the TOTP outcome, the credential read-back is never invoked). The gate's+ # `not is_totp_value` conjunct is a defensive backstop for this invariant.+ el = _mock_input({"type": "password", "autocomplete": None, "name": "otp"})++ results, card_readback, tel_verify, phone_format, _, _, secret_readback = await _run_input_text(+ el, "{{ totp }}", resolved=str(BitwardenConstants.TOTP)+ )++ assert len(results) == 1 and isinstance(results[0], ActionFailure)+ assert results[0].exception_type == "NoTOTPSecretFound"+ secret_readback.assert_not_awaited()+ card_readback.assert_not_awaited()