-
Notifications
You must be signed in to change notification settings - Fork 5
Toggle password #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Toggle password #206
Conversation
Reviewer's GuideThis pull request implements a password visibility toggle by introducing a Symfony form type extension, registering it as a service, wiring in a Stimulus controller, updating Twig and SCSS assets, enhancing translations, updating documentation, and removing the previous UX package dependency. Sequence diagram for password visibility toggle interactionsequenceDiagram
actor User
participant PasswordInput as Password Input Field
participant ToggleButton as Toggle Button
participant StimulusController as Stimulus Controller
User->>ToggleButton: Clicks toggle button
ToggleButton->>StimulusController: Event: click
StimulusController->>PasswordInput: Change type (password/text)
StimulusController->>ToggleButton: Update label and icon
Class diagram for TogglePasswordTypeExtensionclassDiagram
class TogglePasswordTypeExtension {
- TranslatorInterface translator
+ __construct(translator: TranslatorInterface|null)
+ getExtendedTypes(): iterable
+ configureOptions(resolver: OptionsResolver): void
+ buildView(view: FormView, form: FormInterface, options: array): void
- translateLabel(label: string|TranslatableMessage|null, translationDomain: string|null): string|null
}
TogglePasswordTypeExtension --|> AbstractTypeExtension
Class diagram for Stimulus toggle_password_controller.jsclassDiagram
class TogglePasswordController {
+ visibleLabelValue: String
+ visibleIconValue: String
+ hiddenLabelValue: String
+ hiddenIconValue: String
+ buttonClassesValue: Array
- isDisplayed: Boolean
- visibleIcon: String
- hiddenIcon: String
+ connect(): void
+ createButton(): HTMLButtonElement
+ toggle(event): void
+ dispatchEvent(name: String, payload: Object): void
}
TogglePasswordController --|> Controller
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
Blocking issues:
- User controlled data in methods like
innerHTML
,outerHTML
ordocument.write
is an anti-pattern that can lead to XSS vulnerabilities (link) - User controlled data in a
button.innerHTML
is an anti-pattern that can lead to XSS vulnerabilities (link) - User controlled data in methods like
innerHTML
,outerHTML
ordocument.write
is an anti-pattern that can lead to XSS vulnerabilities (link) - User controlled data in a
toggleButtonElement.innerHTML
is an anti-pattern that can lead to XSS vulnerabilities (link)
General comments:
- The service definition for TogglePasswordTypeExtension reuses the ‘framework.collection_type_extension’ ID and will override your collection extension; give it a unique service ID (e.g. ‘framework.toggle_password_type_extension’) and tag it appropriately.
- Using bare translation keys like “Show” and “Hide” risks collisions in large apps; consider namespacing them (e.g. ‘toggle_password.show’, ‘toggle_password.hide’) in your message files.
- In the docs snippet, the array entry 'use_toggle_form_theme' => false is missing a trailing comma—adding it will prevent a PHP parse error.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The service definition for TogglePasswordTypeExtension reuses the ‘framework.collection_type_extension’ ID and will override your collection extension; give it a unique service ID (e.g. ‘framework.toggle_password_type_extension’) and tag it appropriately.
- Using bare translation keys like “Show” and “Hide” risks collisions in large apps; consider namespacing them (e.g. ‘toggle_password.show’, ‘toggle_password.hide’) in your message files.
- In the docs snippet, the array entry 'use_toggle_form_theme' => false is missing a trailing comma—adding it will prevent a PHP parse error.
## Individual Comments
### Comment 1
<location> `assets-public/controllers/toggle_password_controller.js:44` </location>
<code_context>
+ const button = document.createElement('button')
+ button.type = 'button'
+ button.classList.add(...this.buttonClassesValue)
+ button.setAttribute('tabindex', '-1')
+ button.addEventListener('click', this.toggle.bind(this))
+ button.innerHTML = `${this.visibleIcon} ${this.visibleLabelValue}`
</code_context>
<issue_to_address>
Setting tabindex to -1 prevents keyboard navigation to the toggle button.
Users who rely on keyboard navigation will be unable to access the toggle button. To maintain accessibility, use tabindex="0" or omit it.
</issue_to_address>
## Security Issues
### Issue 1
<location> `assets-public/controllers/toggle_password_controller.js:46` </location>
<issue_to_address>
**security (javascript.browser.security.insecure-document-method):** User controlled data in methods like `innerHTML`, `outerHTML` or `document.write` is an anti-pattern that can lead to XSS vulnerabilities
*Source: opengrep*
</issue_to_address>
### Issue 2
<location> `assets-public/controllers/toggle_password_controller.js:46` </location>
<issue_to_address>
**security (javascript.browser.security.insecure-innerhtml):** User controlled data in a `button.innerHTML` is an anti-pattern that can lead to XSS vulnerabilities
*Source: opengrep*
</issue_to_address>
### Issue 3
<location> `assets-public/controllers/toggle_password_controller.js:56` </location>
<issue_to_address>
**security (javascript.browser.security.insecure-document-method):** User controlled data in methods like `innerHTML`, `outerHTML` or `document.write` is an anti-pattern that can lead to XSS vulnerabilities
*Source: opengrep*
</issue_to_address>
### Issue 4
<location> `assets-public/controllers/toggle_password_controller.js:56` </location>
<issue_to_address>
**security (javascript.browser.security.insecure-innerhtml):** User controlled data in a `toggleButtonElement.innerHTML` is an anti-pattern that can lead to XSS vulnerabilities
*Source: opengrep*
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
const button = document.createElement('button') | ||
button.type = 'button' | ||
button.classList.add(...this.buttonClassesValue) | ||
button.setAttribute('tabindex', '-1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Setting tabindex to -1 prevents keyboard navigation to the toggle button.
Users who rely on keyboard navigation will be unable to access the toggle button. To maintain accessibility, use tabindex="0" or omit it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Te bekijken lijkt me.
button.classList.add(...this.buttonClassesValue) | ||
button.setAttribute('tabindex', '-1') | ||
button.addEventListener('click', this.toggle.bind(this)) | ||
button.innerHTML = `${this.visibleIcon} ${this.visibleLabelValue}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
security (javascript.browser.security.insecure-document-method): User controlled data in methods like innerHTML
, outerHTML
or document.write
is an anti-pattern that can lead to XSS vulnerabilities
Source: opengrep
button.classList.add(...this.buttonClassesValue) | ||
button.setAttribute('tabindex', '-1') | ||
button.addEventListener('click', this.toggle.bind(this)) | ||
button.innerHTML = `${this.visibleIcon} ${this.visibleLabelValue}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
security (javascript.browser.security.insecure-innerhtml): User controlled data in a button.innerHTML
is an anti-pattern that can lead to XSS vulnerabilities
Source: opengrep
toggleButtonElement.innerHTML = this.isDisplayed | ||
? `${this.hiddenIcon} ${this.hiddenLabelValue}` | ||
: `${this.visibleIcon} ${this.visibleLabelValue}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
security (javascript.browser.security.insecure-document-method): User controlled data in methods like innerHTML
, outerHTML
or document.write
is an anti-pattern that can lead to XSS vulnerabilities
Source: opengrep
toggleButtonElement.innerHTML = this.isDisplayed | ||
? `${this.hiddenIcon} ${this.hiddenLabelValue}` | ||
: `${this.visibleIcon} ${this.visibleLabelValue}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
security (javascript.browser.security.insecure-innerhtml): User controlled data in a toggleButtonElement.innerHTML
is an anti-pattern that can lead to XSS vulnerabilities
Source: opengrep
export default class extends Controller { | ||
static values = { | ||
visibleLabel: { type: String, default: 'Show' }, | ||
visibleIcon: { type: String, default: 'Default' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Voor mij moeten die icons niet configureerbaar zijn. Is enkel maar bloated code. Tenzij anderen daar een andere mening over hebben natuurlijk.
const button = document.createElement('button') | ||
button.type = 'button' | ||
button.classList.add(...this.buttonClassesValue) | ||
button.setAttribute('tabindex', '-1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Te bekijken lijkt me.
'use_toggle_form_theme' => false | ||
|
||
// Customizing labels and icons | ||
'hidden_label' => 'Masquer', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventueel ook echt met translation service in voorbeeld steken. Zodat mensen het kunnen kopiëren.
|
||
## Password Visibility Toggle | ||
|
||
This works automatically when you use the `PasswordType` or `RepeatedPasswordStrengthType` in your form type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zet een voorbeeld zodat mensen het eenvoudig kunnen kopiëren .
|
||
'Text copied!': 'Test copied!' | ||
'Postcode and municipality': Postcode and municipality | ||
Show: Show |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misschien beter Show password
en Hide password
gebruiken als labels. Die zijn minder generiek.
Summary by Sourcery
Add a configurable password visibility toggle to Symfony forms by implementing a PasswordType extension, Stimulus controller, accompanying assets, translations, and documentation, replacing the previous UX dependency
New Features:
Enhancements:
Build:
Documentation: