Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fill_login: fill a sign-in page's only password box when it is marked new-password

AdityaUmale525919f30c05
diff --git a/server/login-fill.test.ts b/server/login-fill.test.ts
index 64888b0dd5..d6abdf98b7 100644
--- a/server/login-fill.test.ts
+++ b/server/login-fill.test.ts
@@ -341,6 +341,28 @@ describe("one-time codes and fields", () => {
expect(page.field("input[name=new]").value).toBe("");
});
+ it("takes a sign-in page's only password box even when it is marked new-password, as TikTok's is", async () => {
+ const { page, fill } = setup("https://www.tiktok.com/login/phone-or-email/email", `<form><input type="text" placeholder="Email or username" autocomplete="webauthn" name="username"><input type="password" placeholder="Password" autocomplete="new-password"></form>`,
+ [{ host: "tiktok.com", username: "[email protected]" }]);
+ page.answer = () => ({ navigate: DASHBOARD });
+ const outcome = await fill();
+ expect(outcome).toMatchObject({ ok: true, filled: ["username", "password"] });
+ expect(page.typed).toEqual(["[email protected]", PASSWORD]);
+ expect(page.pressed).toEqual(["Enter"]);
+ });
+
+ it("keeps new-password boxes empty on a sign-in page with two of them, or on a sign-up page under a sign-in path", async () => {
+ const twoBoxes = `<form><input name="email" type="email"><input name="new" type="password" autocomplete="new-password"><input name="again" type="password" autocomplete="new-password"></form>`;
+ const oneBox = `<form><input name="email" type="email"><input name="new" type="password" autocomplete="new-password"></form>`;
+ for (const [url, html] of [["https://example.com/login", twoBoxes], ["https://example.com/login/signup", oneBox], ["https://example.com/signin/reset-password", oneBox]]) {
+ const { page, fill } = setup(url, html, [{ host: "example.com", username: "[email protected]" }], { submit: false });
+ const outcome = await fill();
+ expect(outcome).toMatchObject({ ok: true, filled: ["username"] });
+ expect(page.field("input[name=new]").value).toBe("");
+ page.close();
+ }
+ });
+
it("asks which login when a site has several, and fills the one named", async () => {
const saved = [{ host: "example.com", username: "alice", password: "fake-alice-pw" }, { host: "example.com", username: "bob", password: "fake-bob-pw" }];
const { page, fill } = setup("https://example.com/login", LOGIN_FORM, saved, { submit: false });
diff --git a/server/login-fill.ts b/server/login-fill.ts
index f1b6994776..a474a2952e 100644
--- a/server/login-fill.ts
+++ b/server/login-fill.ts
@@ -170,8 +170,15 @@ const FIND_FIELDS = `((nonce, step) => {
const inputs = all("input").filter(usable);
const codes = inputs.filter(isCode);
const rest = inputs.filter((el) => !codes.includes(el));
- const passwords = rest.filter((el) => el.type === "password" && !tokens(el).includes("new-password"));
- const password = passwords.find((el) => tokens(el).includes("current-password")) || passwords[0] || null;
+ const isNew = (el) => tokens(el).includes("new-password");
+ const passwords = rest.filter((el) => el.type === "password" && !isNew(el));
+ const fresh = rest.filter((el) => el.type === "password" && isNew(el));
+ // Some sign-in forms (TikTok's) mark their only password box new-password.
+ const steps = location.pathname.toLowerCase().split("/");
+ const signIn = steps.some((step) => ["login", "log-in", "signin", "sign-in"].includes(step)) &&
+ !steps.some((step) => ["signup", "sign-up", "register", "join", "reset", "forgot", "change"].some((word) => step.includes(word)));
+ const password = passwords.find((el) => tokens(el).includes("current-password")) || passwords[0] ||
+ (signIn && fresh.length === 1 ? fresh[0] : null);
const USER = /user|e-?mail|login|account|identifier|phone|mobile/;
const userLike = (el) => tokens(el).includes("username") || tokens(el).includes("email") || el.type === "email" || (plain(el) && USER.test(hint(el)));
let username = null;