| @@ -31,8 +31,15 @@ | ||
| 31 | 31 | // is total_max_points(), which sums the declared "max" of every category |
| 32 | 32 | // in get_categories(). Bump this only when manually verifying the sum. |
| 33 | 33 | const TOTAL_MAX_POINTS = 106; |
| 34 | 34 | const REGRESSION_THRESHOLD = 10; // Points dropped before sending the alert email. |
| 35 | + /* | |
| 36 | + * Highest score a site can show while the self-protection check reports | |
| 37 | + * tampering: every other result of this report was computed by the same | |
| 38 | + * code whose files were reported as changed, so a high number next to it | |
| 39 | + * would be a lie. 29 is the top of grade E in compute_grade(). | |
| 40 | + */ | |
| 41 | + const SCORE_CAP_ON_TAMPER = 29; | |
| 35 | 42 | |
| 36 | 43 | /** |
| 37 | 44 | * Sum of the declared "max" of every category. This is the canonical |
| 38 | 45 | * maximum a scan can earn. Using this instead of the constant prevents |
| @@ -96,9 +103,11 @@ | ||
| 96 | 103 | 'label' => __( 'Internal Checks (exclusive)', 'vigilante' ), |
| 97 | 104 | // Sum of the max values of every check in |
| 98 | 105 | // Vigilante_SA_Category_Internal. Update when adding/removing |
| 99 | 106 | // checks or changing their max value. |
| 100 | - 'max' => 30, | |
| 107 | + // 3.0.0: 30 -> 40 (self_integrity check added, worth 10: the | |
| 108 | + // integrity of the plugin that runs every other check). | |
| 109 | + 'max' => 40, | |
| 101 | 110 | ), |
| 102 | 111 | 'reputation' => array( |
| 103 | 112 | 'slug' => 'reputation', |
| 104 | 113 | 'label' => __( 'Reputation / Blacklists', 'vigilante' ), |
| @@ -261,8 +270,24 @@ | ||
| 261 | 270 | // Normalize against the declared category max so skipped checks don't erode the score. |
| 262 | 271 | $declared_max = self::total_max_points(); |
| 263 | 272 | $grade = Vigilante_SA_Helpers::compute_grade( $total_earned, $declared_max ); |
| 264 | 273 | |
| 274 | + // Self-protection caps the score (see SCORE_CAP_ON_TAMPER). The same | |
| 275 | + // cap is applied when phases are merged, in rebuild_from_categories(). | |
| 276 | + $capped_by = ''; | |
| 277 | + foreach ( $results as $r ) { | |
| 278 | + if ( $r instanceof Vigilante_SA_Check_Result | |
| 279 | + && 'self_integrity' === $r->id | |
| 280 | + && Vigilante_SA_Check_Result::STATE_FAIL === $r->state ) { | |
| 281 | + $capped_by = 'self_integrity'; | |
| 282 | + break; | |
| 283 | + } | |
| 284 | + } | |
| 285 | + if ( 'self_integrity' === $capped_by && $grade['score'] > self::SCORE_CAP_ON_TAMPER ) { | |
| 286 | + $grade['score'] = self::SCORE_CAP_ON_TAMPER; | |
| 287 | + $grade['grade'] = 'E'; | |
| 288 | + } | |
| 289 | + | |
| 265 | 290 | return array( |
| 266 | 291 | 'ran_at' => $started, |
| 267 | 292 | 'phase' => $phase, |
| 268 | 293 | 'total_earned' => $total_earned, |
| @@ -269,8 +294,9 @@ | ||
| 269 | 294 | 'total_max' => $declared_max, |
| 270 | 295 | 'total_evaluated'=> $total_max, // Actual evaluated max (excluding skipped). |
| 271 | 296 | 'score' => $grade['score'], |
| 272 | 297 | 'grade' => $grade['grade'], |
| 298 | + 'capped_by' => $capped_by, | |
| 273 | 299 | 'counts' => $counts, |
| 274 | 300 | 'categories' => $categories, |
| 275 | 301 | ); |
| 276 | 302 | } |
| @@ -392,8 +418,24 @@ | ||
| 392 | 418 | |
| 393 | 419 | $total_max = self::total_max_points(); |
| 394 | 420 | $grade = Vigilante_SA_Helpers::compute_grade( $total_earned, $total_max ); |
| 395 | 421 | |
| 422 | + // Self-protection caps the score (see SCORE_CAP_ON_TAMPER). | |
| 423 | + $capped_by = ''; | |
| 424 | + foreach ( $categories as $cat ) { | |
| 425 | + foreach ( (array) $cat['checks'] as $c ) { | |
| 426 | + if ( 'self_integrity' === ( isset( $c['id'] ) ? $c['id'] : '' ) | |
| 427 | + && Vigilante_SA_Check_Result::STATE_FAIL === ( isset( $c['state'] ) ? $c['state'] : '' ) ) { | |
| 428 | + $capped_by = 'self_integrity'; | |
| 429 | + break 2; | |
| 430 | + } | |
| 431 | + } | |
| 432 | + } | |
| 433 | + if ( 'self_integrity' === $capped_by && $grade['score'] > self::SCORE_CAP_ON_TAMPER ) { | |
| 434 | + $grade['score'] = self::SCORE_CAP_ON_TAMPER; | |
| 435 | + $grade['grade'] = 'E'; | |
| 436 | + } | |
| 437 | + | |
| 396 | 438 | return array( |
| 397 | 439 | 'categories' => $categories, |
| 398 | 440 | 'total_earned' => $total_earned, |
| 399 | 441 | 'total_max' => $total_max, |
| @@ -399,8 +441,9 @@ | ||
| 399 | 441 | 'total_max' => $total_max, |
| 400 | 442 | 'total_evaluated'=> $total_evaluated, |
| 401 | 443 | 'score' => $grade['score'], |
| 402 | 444 | 'grade' => $grade['grade'], |
| 445 | + 'capped_by' => $capped_by, | |
| 403 | 446 | 'counts' => $counts, |
| 404 | 447 | ); |
| 405 | 448 | } |
| 406 | 449 | |