Skip to content

Commit

Permalink
UI/Init: Add autocomplete="off" for password fields (#6149)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbongers-cat authored Aug 18, 2023
1 parent 335e461 commit d47d3d6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Services/Init/classes/class.ilStartUpGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ protected function initStandardLoginForm(): ilPropertyFormGUI
$pi->setRetype(false);
$pi->setSkipSyntaxCheck(true);
$pi->setSize(20);
$pi->setDisableHtmlAutoComplete(false);
$pi->setDisableHtmlAutoComplete(true);
$pi->setRequired(true);
$form->addItem($pi);

Expand Down
6 changes: 6 additions & 0 deletions src/UI/Component/Input/Field/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ public function tag(string $label, array $tags, ?string $byline = null): Tag;
* rules:
* usage:
* 1: Password Input MUST be used for passwords.
* composition:
* 1: >
* The input MUST always be rendered with the attribute autocomplete="off".
* This advises browsers to NOT autofill the input field with cached passwords
* and avoids potential exposure of confidential data, especially in
* shared environments.
* interaction:
* 1: >
* Password Input SHOULD NOT limit the number of characters.
Expand Down
2 changes: 1 addition & 1 deletion src/UI/templates/default/Input/tpl.password.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="il-input-password" id="{ID_CONTAINER}">
<input id="{ID}" type="password" name="{NAME}"<!-- BEGIN value --> value="{VALUE}"<!-- END value --><!-- BEGIN disabled --> {DISABLED}<!-- END disabled --> class="form-control form-control-sm" />
<input id="{ID}" type="password" name="{NAME}"<!-- BEGIN value --> value="{VALUE}"<!-- END value --><!-- BEGIN disabled --> {DISABLED}<!-- END disabled --> class="form-control form-control-sm" autocomplete="off" />
<!-- BEGIN revelation -->
<span class="revelation-glyph revelation-reveal">
{PASSWORD_REVEAL}
Expand Down
27 changes: 13 additions & 14 deletions tests/UI/Component/Input/Field/PasswordInputTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -17,6 +15,7 @@
* https://github.com/ILIAS-eLearning
*
*********************************************************************/
declare(strict_types=1);

require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
require_once(__DIR__ . "/../../../Base.php");
Expand Down Expand Up @@ -90,12 +89,12 @@ public function test_render(): void
$r = $this->getDefaultRenderer();
$expected = '
<div class="form-group row">
<label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">'.$label.'</label>
<label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">' . $label . '</label>
<div class="col-sm-8 col-md-9 col-lg-10">
<div class="il-input-password" id="id_1_container">
<input id="id_1" type="password" name="'.$name.'" class="form-control form-control-sm" />
<input id="id_1" type="password" name="' . $name . '" class="form-control form-control-sm" autocomplete="off" />
</div>
<div class="help-block">'.$byline.'</div>
<div class="help-block">' . $byline . '</div>
</div>
</div>';
$this->assertHTMLEquals($expected, $r->render($pwd));
Expand All @@ -116,7 +115,7 @@ public function test_render_error(): void
<label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
<div class="col-sm-8 col-md-9 col-lg-10">
<div class="help-block alert alert-danger" aria-describedby="id_1" role="alert">an_error</div>
<div class="il-input-password" id="id_1_container"><input id="id_1" type="password" name="name_0" class="form-control form-control-sm" /></div>
<div class="il-input-password" id="id_1_container"><input id="id_1" type="password" name="name_0" class="form-control form-control-sm" autocomplete="off" /></div>
<div class="help-block">byline</div>
</div>
</div>');
Expand All @@ -134,10 +133,10 @@ public function test_render_no_byline(): void
$r = $this->getDefaultRenderer();
$expected = '
<div class="form-group row">
<label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">'.$label.'</label>
<label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">' . $label . '</label>
<div class="col-sm-8 col-md-9 col-lg-10">
<div class="il-input-password" id="id_1_container">
<input id="id_1" type="password" name="'.$name.'" class="form-control form-control-sm" />
<input id="id_1" type="password" name="' . $name . '" class="form-control form-control-sm" autocomplete="off" />
</div>
</div>
</div>';
Expand All @@ -155,10 +154,10 @@ public function test_render_value(): void
$r = $this->getDefaultRenderer();
$expected = '
<div class="form-group row">
<label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">'.$label.'</label>
<label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">' . $label . '</label>
<div class="col-sm-8 col-md-9 col-lg-10">
<div class="il-input-password" id="id_1_container">
<input id="id_1" type="password" name="'.$name.'" value="'.$value.'" class="form-control form-control-sm" />
<input id="id_1" type="password" name="' . $name . '" value="' . $value . '" class="form-control form-control-sm" autocomplete="off" />
</div>
</div>
</div>';
Expand All @@ -177,10 +176,10 @@ public function test_render_required(): void

$expected = '
<div class="form-group row">
<label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">'.$label.'<span class="asterisk">*</span></label>
<label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">' . $label . '<span class="asterisk">*</span></label>
<div class="col-sm-8 col-md-9 col-lg-10">
<div class="il-input-password" id="id_1_container">
<input id="id_1" type="password" name="'.$name.'" class="form-control form-control-sm" />
<input id="id_1" type="password" name="' . $name . '" class="form-control form-control-sm" autocomplete="off" />
</div>
</div>
</div>';
Expand All @@ -199,10 +198,10 @@ public function test_render_disabled(): void

$expected = '
<div class="form-group row">
<label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">'.$label.'</label>
<label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">' . $label . '</label>
<div class="col-sm-8 col-md-9 col-lg-10">
<div class="il-input-password" id="id_1_container">
<input id="id_1" type="password" name="'.$name.'" disabled="disabled" class="form-control form-control-sm" />
<input id="id_1" type="password" name="' . $name . '" disabled="disabled" class="form-control form-control-sm" autocomplete="off" />
</div>
</div>
</div>';
Expand Down

0 comments on commit d47d3d6

Please sign in to comment.