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

enforce configuration of Safe Browsing API key (#104) #108

Merged
merged 1 commit into from
Nov 3, 2023

Conversation

stklcode
Copy link
Contributor

@stklcode stklcode commented Apr 11, 2021

Second stage of #104 and follow-up to #105.

The warning that will be introduces in 1.4.3 (#105) is now an error. On plugin activation Safe Browsing will be deactivated, if no key is provided. In the settings UI, the field is not "required" (should be no problem, because is it also "disabled" if the checkbox is unchecked) and if for whatever reason the configuration is saved without a key, an error will be displayed.

If again for any reason the check is triggered without a key, the fallback is no longer be used and the check is skipped.

@stklcode stklcode added this to the 1.5.0 milestone Apr 11, 2021
@stklcode stklcode force-pushed the feature/104-enforce-safebrowsing-key branch 2 times, most recently from 46caab0 to e12e543 Compare April 11, 2021 10:40
@stklcode stklcode force-pushed the feature/104-enforce-safebrowsing-key branch from e12e543 to 27cc83a Compare May 15, 2021 08:01
@stklcode stklcode marked this pull request as ready for review May 26, 2021 07:39
if ( self::_get_option( 'safe_browsing' ) && empty( $safe_browsing_key ) ) {
self::_update_option( 'safe_browsing', 0 );
set_transient( 'antivirus-activation-notice', true, 2592000 );
}
Copy link
Member

Choose a reason for hiding this comment

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

In my manual tests the admin notice was never shown. When (re)activating AntiVirus, all options are cleared in ll. 138-143. Therefore the condition in l. 152 can never be true, right?

This check be run independent of activation, shouldn't it? I. e. after the update or in the check_safe_browsing() method itself? Then we even cover cases such as updating incl. the correction + warning and importing a DB backup afterwards - check is repeated and results in showing the warning again.

Copy link
Contributor Author

@stklcode stklcode May 28, 2021

Choose a reason for hiding this comment

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

I'll take a look at the implementation again, possibly something got lost or is still incorrect here.

This check be run independent of activation, shouldn't it? I. e. after the update

The check should be run in several places. The one here in the activation hook should be triggered right after plugin activation and as plugins are reactivated after an update, at least once after the update and should notify the administrator that the check has been disabled (if it was enabled without API key before). In this place we set a transient object because the update might be triggered asynchronously so the admin will be informed on the next visit.

Check is also performed when saving settings and right before the check itself, if for any reason the options are stored incorrectly.


When (re)activating AntiVirus, all options are cleared in ll. 138-143.

That's not correct. Options should and must not be cleared on plugin activation, otherwise everything would be reset on updates or reactivation for whatever reason.

From the add_option() reference:

Existing options will not be updated and checks are performed to ensure that you aren’t adding a protected WordPress option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works for me in the intended way:

  • save settings with SB enabled and no API key in v1.4.3 (raises a warning)
  • update plugin to 1.5.0
  • deactivate and activate the plugin (done automatically when updating the regular way)
  • warning is shown once that SB has been disabled
screenshot (animated)

antivirus-104

Copy link
Member

Choose a reason for hiding this comment

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

warning is shown once that SB has been disabled

Could this be displayed until it is actively dismissed? Otherwise it could easily be missed ...

@Zodiac1978 Zodiac1978 linked an issue Jul 20, 2021 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Jul 21, 2021

Codecov Report

Patch coverage: 10.71% and project coverage change: -0.66% ⚠️

Comparison is base (e55943c) 35.93% compared to head (4d7e3be) 35.27%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #108      +/-   ##
=============================================
- Coverage      35.93%   35.27%   -0.66%     
+ Complexity       151      146       -5     
=============================================
  Files              5        5              
  Lines            782      788       +6     
=============================================
- Hits             281      278       -3     
- Misses           501      510       +9     
Files Changed Coverage Δ
antivirus.php 0.00% <ø> (ø)
inc/class-antivirus.php 17.00% <0.00%> (-0.46%) ⬇️
inc/class-antivirus-safebrowsing.php 98.61% <100.00%> (+4.94%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stklcode stklcode force-pushed the feature/104-enforce-safebrowsing-key branch from b5c312f to baf3941 Compare May 11, 2022 18:48
@stklcode stklcode force-pushed the feature/104-enforce-safebrowsing-key branch from baf3941 to 329d258 Compare September 10, 2022 08:18
@stklcode stklcode force-pushed the feature/104-enforce-safebrowsing-key branch from 329d258 to aad7d2c Compare February 9, 2023 11:56
@stklcode stklcode force-pushed the feature/104-enforce-safebrowsing-key branch from aad7d2c to 4d7e3be Compare September 17, 2023 09:48
@pluginkollektiv pluginkollektiv deleted a comment from codecov-io Sep 17, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@Zodiac1978 Zodiac1978 left a comment

Choose a reason for hiding this comment

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

Looks okay to me, but needs testing aftwerwards.

@Zodiac1978
Copy link
Member

Merging is blocked because @patrickrobrecht requested changes. Maybe he can look at it again. Otherwise, I can merge without those changes if necessary.

@stklcode stklcode force-pushed the feature/104-enforce-safebrowsing-key branch from 4d7e3be to 3a059a8 Compare October 31, 2023 15:04
@Zodiac1978
Copy link
Member

Looks like $screen = get_current_screen(); can be removed, because $screen is not used anymore with this PR.

And additionally the comment seems confusing:

Add admin notice to users who can manage options, Safe Browsing has been disabled without custom API key.

Maybe changing it to makes it clearer:

Show admin notice to users who can manage options that Safe Browsing has been disabled because custom API key is missing.

@stklcode stklcode force-pushed the feature/104-enforce-safebrowsing-key branch from 0cbc229 to 043408b Compare November 3, 2023 08:32
The built-in fallback API key must not be used anymore. Enforce
configuration of a custom API key and deactivate the feature, if none
is provided.
@stklcode stklcode force-pushed the feature/104-enforce-safebrowsing-key branch from 043408b to ef265c9 Compare November 3, 2023 08:34
Copy link

sonarqubecloud bot commented Nov 3, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

3.8% 3.8% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@Zodiac1978 Zodiac1978 merged commit 2b26f66 into develop Nov 3, 2023
@stklcode stklcode deleted the feature/104-enforce-safebrowsing-key branch November 3, 2023 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove fallback API key for Google SafeBrowsing API
4 participants