From f873f4b369d2bfafb23b0726febb7480bbbbdfb5 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 18 Sep 2024 23:10:31 +0200 Subject: [PATCH] Add autocomplete attribute to credential fields Prevent browsers from automatically autofilling the password entry box for the Factorio credentials by setting the autocomplete property to new-password on the password input. --- packages/lib/src/config/classes.ts | 6 ++++++ packages/lib/src/config/definitions.ts | 4 ++++ packages/web_ui/src/components/BaseConfigTree.tsx | 6 +++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/lib/src/config/classes.ts b/packages/lib/src/config/classes.ts index 43903fbb..8e3a16ee 100644 --- a/packages/lib/src/config/classes.ts +++ b/packages/lib/src/config/classes.ts @@ -77,6 +77,12 @@ export interface FieldDefinition { * Text used to describe the config field in user interfaces. */ description?: string; + /** + * Value to use for the autocomplete attribute in the Web UI's input element. + * Useful for making browsers behave properly with credential inputs. + * Only used for string and number fields. + */ + autoComplete?: string; /** * Web UI component to use for rending this input. Can be extended by * @{link "@clusterio/web_ui".BaseWebPlugin.inputComponents} diff --git a/packages/lib/src/config/definitions.ts b/packages/lib/src/config/definitions.ts index 8f38de08..aafce8f1 100644 --- a/packages/lib/src/config/definitions.ts +++ b/packages/lib/src/config/definitions.ts @@ -153,12 +153,14 @@ export class ControllerConfig extends classes.Config { "controller.factorio_username": { title: "Factorio Username", description: "Username to authenticate with Factorio API with.", + autoComplete: "section-factorio username", type: "string", optional: true, }, "controller.factorio_token": { title: "Factorio Token", description: "Token to authenticate with Factorio API with.", + autoComplete: "section-factorio new-password", type: "string", credential: ["controller"], optional: true, @@ -276,6 +278,7 @@ export class HostConfig extends classes.Config { description: "Username to authenticate with Factorio API with. If set this will be used in the server settings " + "of all instances on this host.", + autoComplete: "section-factorio username", type: "string", optional: true, }, @@ -284,6 +287,7 @@ export class HostConfig extends classes.Config { description: "Token to authenticate with Factorio API with. If set this will be used in the server settings " + "of all instances on this host.", + autoComplete: "section-factorio new-password", type: "string", credential: ["host"], optional: true, diff --git a/packages/web_ui/src/components/BaseConfigTree.tsx b/packages/web_ui/src/components/BaseConfigTree.tsx index 1c994170..b7a309f3 100644 --- a/packages/web_ui/src/components/BaseConfigTree.tsx +++ b/packages/web_ui/src/components/BaseConfigTree.tsx @@ -44,12 +44,12 @@ function renderInput(inputComponents: Record, def: lib.F } if (def.type === "string") { if (def.credential) { - return ; + return ; } - return ; + return ; } if (def.type === "number") { - return ; + return ; } return `Unknown type ${def.type}`;