Skip to content
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

Add restriction on tab opening to the current active tab #13

Merged
merged 2 commits into from
Jan 11, 2024

Conversation

thibmeu
Copy link
Contributor

@thibmeu thibmeu commented Jan 11, 2024

In the existing extension, any tab initiating a PrivateToken request for a trusted issuer is going to trigger the associated attester tab opening. This might interrupt the user flow.
This commit introduces an improvement to only allow the current active tab to open a new tab upon a PrivateToken request.

),
);
if (activeTab !== tabId) {
logger.debug('Not openning a new tab due to requesting tab not being active');
Copy link
Contributor

Choose a reason for hiding this comment

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

typo:

Suggested change
logger.debug('Not openning a new tab due to requesting tab not being active');
logger.debug('Not opening a new tab due to requesting tab not being active');

Observation: this function returns undefined, but the the caller also checks for null. Do you purposefully differentiate between them?

        const redirectPromise = w3HeaderValue
            .then(async (value): Promise<void | chrome.webRequest.BlockingResponse> => {
                if (value === null) { // <-- null check
                    delete TOKENS[details.url];
                    return;
                }
                if (isManifestV3(chrome)) {
                   // ...
                } else {
                    if (value) { // <-- undefined check
                        TOKENS[details.url] = value;
                    }
                }

                return { redirectUrl: details.url };
            })

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I return undefined because that's the normal return path of similar check in this function. However, this does indeed not seem to be a normal validation.
I've pushed a new commit with the correct check !value, which would cover undefined and null (or even empty string, even though we don't expect this value).

The typo has been corrected as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

With the !value change, the second if (value) { check is redundant, it will always be true. LGTM otherwise!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@thibmeu thibmeu force-pushed the feature-limit-tab-opening branch 2 times, most recently from 9ef65bf to 69ab8b4 Compare January 11, 2024 14:18
In the existing extension, any tab initiating a PrivateToken request for
a trusted issuer is going to trigger the associated attester tab
opening. This might interrupt the user flow.
This commit introduces an improvement to only allow the current active
tab to open a new tab upon a PrivateToken request.
`headerToToken` returns `Promise<string | undefined>`. However, the existing
check assessed `headerToToken().then(value => value === null ? something
: somethingElse)`.
This should never be true.
Instead, this check is replaced with `!value`.
@thibmeu
Copy link
Contributor Author

thibmeu commented Jan 11, 2024

PR updated to move from chrome.tab.query to chrome.tab.get with window.focused

@thibmeu thibmeu merged commit 49e764a into cloudflare:main Jan 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants