Skip to content

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

fix(login-fill): treat /login.html as a sign-in page for a lone new-password box

AdityaUmale79b0b8159855
diff --git a/server/login-fill.test.ts b/server/login-fill.test.ts
index 820493d1c8..5a103d75c6 100644
--- a/server/login-fill.test.ts
+++ b/server/login-fill.test.ts
@@ -351,10 +351,22 @@ describe("one-time codes and fields", () => {
expect(page.pressed).toEqual(["Enter"]);
});
+ it("takes the only new-password box on a sign-in page whose path ends in a file name (login.html), as ccopyright's does", async () => {
+ const boxes = `<div><input type="text" placeholder="请输入用户名/手机号/邮箱" autocomplete="new-password"><input type="password" placeholder="请输入密码" autocomplete="new-password"></div>`;
+ for (const url of ["https://register.example.cn/login.html", "https://example.com/account/signin.php", "https://example.com/Sign-In.aspx"]) {
+ const { page, fill } = setup(url, boxes, [{ host: url.includes(".cn") ? "example.cn" : "example.com", username: "[email protected]" }], { submit: false });
+ const outcome = await fill();
+ expect(outcome).toMatchObject({ ok: true, filled: ["username", "password"] });
+ expect(page.field("input[type=text]").value).toBe("[email protected]");
+ expect(page.field("input[type=password]").value).toBe(PASSWORD);
+ page.close();
+ }
+ });
+
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], ["https://example.com/login/registration", oneBox], ["https://example.com/login/%72egistration", oneBox], ["https://example.com/login/%E0%A4%A", oneBox]]) {
+ for (const [url, html] of [["https://example.com/login", twoBoxes], ["https://example.com/login.html", twoBoxes], ["https://example.com/login/signup.html", oneBox], ["https://example.com/login/signup", oneBox], ["https://example.com/signin/reset-password", oneBox], ["https://example.com/login/registration", oneBox], ["https://example.com/login/%72egistration", oneBox], ["https://example.com/login/%E0%A4%A", 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"] });
diff --git a/server/login-fill.ts b/server/login-fill.ts
index 413c61eaa6..69fc7d7fd4 100644
--- a/server/login-fill.ts
+++ b/server/login-fill.ts
@@ -174,7 +174,7 @@ const FIND_FIELDS = `((nonce, step) => {
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 = (() => { try { return location.pathname.split("/").map((step) => decodeURIComponent(step).toLowerCase()); } catch { return []; } })();
+ const steps = (() => { try { return location.pathname.split("/").map((step) => decodeURIComponent(step).toLowerCase().replace(/\\.[a-z0-9]{1,6}$/, "")); } catch { return []; } })();
const signIn = steps.some((step) => ["login", "log-in", "signin", "sign-in"].includes(step)) &&
!steps.some((step) => ["signup", "sign-up", "register", "registration", "join", "reset", "forgot", "change"].some((word) => step.includes(word)));
const password = passwords.find((el) => tokens(el).includes("current-password")) || passwords[0] ||