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

CANTINA-995: Disable crawling for VIP convenience domains #5129

Merged
merged 1 commit into from
Jan 5, 2024

Conversation

rebeccahum
Copy link
Contributor

@rebeccahum rebeccahum commented Jan 4, 2024

Description

Should be no change functionally since we are moving this logic into MU-plugins.

Pre-review checklist

Please make sure the items below have been covered before requesting a review:

  • This change works and has been tested locally (or has an appropriate fallback).
  • This change works and has been tested on a Go sandbox.
  • This change has relevant unit tests (if applicable).
  • This change uses a rollout method to ease with deployment (if applicable - especially for large scale actions that require writes).
  • This change has relevant documentation additions / updates (if applicable).
  • I've created a changelog description that aligns with the provided examples.

Pre-deploy checklist

  • VIP staff: Ensure any alerts added/updated conform to internal standards (see internal documentation).

Steps to Test

  1. Pull the latest version of vip-cli to incorporate this nginx update change and then, link it
  2. To test with dev-env, change the line if ( false !== strpos( $host, '.go-vip.co' ) || false !== strpos( $host, '.go-vip.net' ) ) { to if ( false !== strpos( $host, '.vip-dev.lndo.site' ) || false !== strpos( $host, '.go-vip.net' ) ) {

Copy link

sonarqubecloud bot commented Jan 4, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

1 New issue
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@rebeccahum rebeccahum marked this pull request as ready for review January 4, 2024 20:37
@rebeccahum rebeccahum requested a review from a team as a code owner January 4, 2024 20:37
Copy link

codecov bot commented Jan 4, 2024

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (6b9b00d) 28.84% compared to head (e04a243) 28.76%.

Files Patch % Lines
001-core/privacy.php 0.00% 7 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #5129      +/-   ##
=============================================
- Coverage      28.84%   28.76%   -0.08%     
  Complexity      4775     4775              
=============================================
  Files            279      279              
  Lines          21005    21000       -5     
=============================================
- Hits            6059     6041      -18     
- Misses         14946    14959      +13     

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

@rebeccahum rebeccahum merged commit 62d680c into develop Jan 5, 2024
37 of 38 checks passed
@rebeccahum rebeccahum deleted the cantina-995 branch January 5, 2024 16:40
return $output;
}
// phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.robots_txt
add_filter( 'robots_txt', __NAMESPACE__ . '\vip_convenience_domain_robots_txt' );
Copy link
Contributor

Choose a reason for hiding this comment

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

WP must have loaded by this point to be able to use add_filter(). Has any customer application code been loaded yet? i.e. this being run at priority 10 isn't going to overwrite any existing changes they may have made?

But, they still have chance to unhook it if they wish? Would be good to document an example of the right hook and process to run that remove_filter( 'robots_txt', '\Automattic\VIP\Core\Privacy\vip_convenience_domain_robots_txt' ) call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No customer application code should be loaded at this point yet. But yeah, @yolih, if you wanted to add this to documentation, that'd be fine.

*/
function vip_convenience_domain_robots_txt( $output ) {
$host = strtolower( $_SERVER['HTTP_HOST'] ?? '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( false !== strpos( $host, '.go-vip.co' ) || false !== strpos( $host, '.go-vip.net' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these check for the strings at the end of the $host, rather than just the presence of it? develop.go-vip.company.com would satisfy this condition, for instance.

Does any IPv4 or IPv6 need to be taken into account as potential values of $host?

* @return string The modified robots.txt content.
*/
function vip_convenience_domain_robots_txt( $output ) {
$host = strtolower( $_SERVER['HTTP_HOST'] ?? '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
Copy link
Contributor

Choose a reason for hiding this comment

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

Is $_SERVER['HTTP_HOST'] set for curl requests?

I see the nullcoalescing, but want to avoid customers making requests with curl and a browser on their convenience domain sites and getting different results.

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 think so, unless the host parameter is set otherwise?

function vip_convenience_domain_robots_txt( $output ) {
$host = strtolower( $_SERVER['HTTP_HOST'] ?? '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( false !== strpos( $host, '.go-vip.co' ) || false !== strpos( $host, '.go-vip.net' ) ) {
$output = "# Crawling is blocked for go-vip.co and go-vip.net domains\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$output = "# Crawling is blocked for go-vip.co and go-vip.net domains\n";
$output = "# Crawling is blocked for go-vip.co and go-vip.net domains.\n";

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