Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: make input HTML IDs unique in authorization-popup.jsx #9390

Merged
merged 4 commits into from
Nov 22, 2023
Merged

fix: make input HTML IDs unique in authorization-popup.jsx #9390

merged 4 commits into from
Nov 22, 2023

Conversation

sethidden
Copy link
Contributor

@sethidden sethidden commented Nov 16, 2023

The HTML id= params "client_id" and "client_secret" applied to inputs in the autorization modal can become duplicated. HTML IDs are supposed to be unique within the document. This breaks password manager (1Password at least) prefills, as it gets confused about which field is which

Description

Before you write me off as some HTML spec purist, the duplicate IDs actually break password managers.
There's a feature in 1Password where you can create a custom field with the same name as an input's ID
Like this (custom_id, client_secret, oauth_username, oauth_password):
image

Before the PR

Now, you may try and happily go to the Swagger authorization-popup.jsx view and try to prefill your fancy new entry and hope it matches the values to inputs correctly, but you will be met with this:
image

Unfortunately, as you can see above, 1Password prefilled the first 3 fields correctly, but failed to fill the client_secret field.

You can go here to inspect the Swagger html yourself: https://spartacus-demo.eastus.cloudapp.azure.com:8443/occ/v2/swagger-ui/index.html

First client_secret input: (the one we wanted to be autofilled by 1Passowrd but wasn't)
image

Second client_secret input: (the one that was wrongly autofilled by 1password)
image

As you can see, the IDs are exactly the same, which is why 1Password gets confused.


After the PR

With my PR, the inputs between sections have the _{flow} suffix, so they're unique. I added them for both the client_id and client_secret, even though only client_secret was problematic:

image

With my PR, we can see that 1Password prefills as expected
First set (the one that previously didn't prefill but now prefills fine):
image
and its complimentary "client_id" field:
image

Second filed (doesn't prefill now):
image

Naturally because the IDs changed I needed to change the 1Password field names as well:
image

Motivation and Context

To improve prefilling Authorization fields with password managers and improve HTML spec compliance.

How Has This Been Tested?

Included in Description section.

Screenshots (if appropriate):

Included in previous sections.

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

In reality this is for 1Password's feature where you can create custom fields named like input IDs and 1Password fill prefill that.
@sethidden sethidden changed the title Make HTML IDs unique in authorization-popup.jsx Make HTML IDs unique in authorization-popup.jsx to improve 1Password integration Nov 16, 2023
@sethidden
Copy link
Contributor Author

You can test this yourself by going to http://localhost:3200/ and putting https://spartacus-demo.eastus.cloudapp.azure.com:8443/occ/v2/api-docs in the bar at the top, then going to Authorize

@sethidden sethidden changed the title Make HTML IDs unique in authorization-popup.jsx to improve 1Password integration fix: make input HTML IDs unique in authorization-popup.jsx Nov 16, 2023
@char0n char0n self-requested a review November 20, 2023 11:53
@char0n char0n self-assigned this Nov 20, 2023
Copy link
Member

@char0n char0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for contributing

@char0n
Copy link
Member

char0n commented Nov 20, 2023

@sethidden you'd have to address the e2e tests before we can merge this.

@sethidden
Copy link
Contributor Author

sethidden commented Nov 20, 2023 via email

@sethidden
Copy link
Contributor Author

@char0n I adjusted both the E2E suites that were failing in the commit 0747e97

Can you re-run the workflows prosim 🇨🇿 ? They need maintainer approval.

Shame I didn't contribute earlier, I was in Prague for a month till yesterday so I could've done it all in Cafedu haha

Copy link
Member

@char0n char0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look fine! Thanks

@char0n
Copy link
Member

char0n commented Nov 22, 2023

Can you re-run the workflows prosim 🇨🇿 ? They need maintainer approval.

Done ;]

@char0n char0n merged commit 9a7c4c0 into swagger-api:master Nov 22, 2023
6 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants