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 support for WPScan API scanning #273

Merged
merged 365 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
365 commits
Select commit Hold shift + click to select a range
817226f
Output name of bot in GitHub reviews; introduce parameter for name of…
gudmdharalds Jul 7, 2022
c47b62e
Renaming constant.
gudmdharalds Jul 7, 2022
49a62ed
Better help message for --name-to-use.
gudmdharalds Jul 7, 2022
99beaa4
Renaming files and test-classes to match file names.
gudmdharalds Jul 7, 2022
5255fc4
Removing severity rating for now.
gudmdharalds Jul 7, 2022
b286e80
Fixing whitespacing.
gudmdharalds Jul 8, 2022
9025803
Remove $options variable.
gudmdharalds Jul 8, 2022
ce76788
Fixing PHPDoc and spacing.
gudmdharalds Jul 8, 2022
22e6322
--wpscan-api-report-end-msg option supports placeholder; update tests.
gudmdharalds Jul 8, 2022
63df6d4
Adding test for vipgoci_wpcore_misc_cleanup_header_comment()
gudmdharalds Jul 8, 2022
4db3825
Adding tests for vipgoci_wpcore_misc_get_file_wp_headers()
gudmdharalds Jul 8, 2022
f2b39fb
Fixing whitespacing.
gudmdharalds Jul 8, 2022
0f5f4c0
Update array for themes.
gudmdharalds Jul 8, 2022
5b8e6c2
Remove temporary file.
gudmdharalds Jul 8, 2022
dfa1641
Ensure to remove temporary file when test is complete.
gudmdharalds Jul 8, 2022
a1161e8
Update PHPCS setting due to changes to pull request needed for #282.
gudmdharalds Jul 8, 2022
26c2479
Add test for vipgoci_wpcore_misc_get_addon_headers_and_type()
gudmdharalds Jul 8, 2022
67453de
vipgoci_wpcore_misc_scan_directory_for_addons(): Search for .css file…
gudmdharalds Jul 8, 2022
597e1ad
Use markTestSkipped() instead of assert() for certain checks.
gudmdharalds Jul 11, 2022
0062aab
Use markTestSkipped() instead of assert() for certain checks.
gudmdharalds Jul 11, 2022
2236063
Adding test for vipgoci_wpcore_misc_scan_directory_for_addons()
gudmdharalds Jul 11, 2022
584c390
Adding helper file for WpcoreMiscScanDirectoryForAdddonsTest test.
gudmdharalds Jul 11, 2022
bc382bf
Adding helper-files to exception list.
gudmdharalds Jul 11, 2022
f91809f
Updating file
gudmdharalds Jul 11, 2022
b0ff56d
Updating file
gudmdharalds Jul 11, 2022
c901ba0
Updating file
gudmdharalds Jul 11, 2022
9f2b908
Updating file
gudmdharalds Jul 11, 2022
24de304
Switching from tar file to directory structure
gudmdharalds Jul 11, 2022
31806ac
Switching from tar file to directory structure
gudmdharalds Jul 11, 2022
281af03
Use assertEquals()
gudmdharalds Jul 11, 2022
3b49502
Skipping fields not needed, adding sanity check.
gudmdharalds Jul 11, 2022
3645c07
Fixing WP CS
gudmdharalds Jul 11, 2022
84568e2
Adding test for vipgoci_wpcore_misc_get_addon_data_and_slugs_for_dire…
gudmdharalds Jul 11, 2022
3cc5dab
Search additional array for results, update comment.
gudmdharalds Jul 11, 2022
ba1f1c8
Adding helper file for WpcoreMiscGetAddonDataAndSlugsForDirectoryTest…
gudmdharalds Jul 11, 2022
7d62c1e
Adding escaping for command.
gudmdharalds Jul 11, 2022
7365595
Escape command
gudmdharalds Jul 11, 2022
9c870ec
Suppress/unsuppress output.
gudmdharalds Jul 11, 2022
a089e60
Suppress/unsuppress output.
gudmdharalds Jul 11, 2022
766f319
Suppress/unsuppress output.
gudmdharalds Jul 11, 2022
0be65aa
Update expected output. Suppress/unsuppress output.
gudmdharalds Jul 11, 2022
81f63b7
Change base directory detection logic.
gudmdharalds Jul 11, 2022
2bb8e6b
Rename file and class.
gudmdharalds Jul 11, 2022
61eaea9
Rename file and class.
gudmdharalds Jul 11, 2022
45fac8c
Rename file and class.
gudmdharalds Jul 11, 2022
38651cc
Removing whitespace.
gudmdharalds Jul 11, 2022
ee7bde6
Removing whitespacing.
gudmdharalds Jul 11, 2022
416990e
Requiring different file.
gudmdharalds Jul 11, 2022
b57adfb
Requiring different file.
gudmdharalds Jul 11, 2022
2ce53e4
Requiring different file.
gudmdharalds Jul 11, 2022
dc68717
Update comment, change how 'local slug' is determined.
gudmdharalds Jul 11, 2022
284baff
Add test for invalid usage of the function.
gudmdharalds Jul 11, 2022
58c35c6
Test when no results are expected.
gudmdharalds Jul 11, 2022
3c485b8
Test if HTML in fields is preserved.
gudmdharalds Jul 11, 2022
a1d1bb4
Test if HTML in fields is preserved.
gudmdharalds Jul 11, 2022
bbc5062
Adding more invalid usage test.
gudmdharalds Jul 11, 2022
d910fb3
Renaming to match test name.
gudmdharalds Jul 11, 2022
a332f08
Renaming to match test name.
gudmdharalds Jul 11, 2022
49a0fb9
Helper files renamed
gudmdharalds Jul 11, 2022
696e130
Adding file.
gudmdharalds Jul 11, 2022
16b7bb3
Adding file
gudmdharalds Jul 11, 2022
d004601
Updating test
gudmdharalds Jul 11, 2022
f73655a
Adding example plugin header file and a non-plugin header file.
gudmdharalds Jul 11, 2022
16030b7
Adding example plugin header file and a non-plugin header file.
gudmdharalds Jul 11, 2022
56b5cd0
Fixing whitespacing
gudmdharalds Jul 11, 2022
f72bbd7
Fix WP CS
gudmdharalds Jul 11, 2022
747fb57
Ensure to set temporary directory to empty on failure.
gudmdharalds Jul 11, 2022
0f75716
If non-false value, will return string indicating that cache was used.
gudmdharalds Jul 12, 2022
9a9618d
Skip submitting WPScan results when relevant label exists.
gudmdharalds Jul 12, 2022
6d0ce30
Do sanity check on results from vipgoci_wpscan_do_scan_via_api()
gudmdharalds Jul 12, 2022
9bed546
Merge branch 'add-wpscan-support' into updates-relating-to-pr273
gudmdharalds Jul 12, 2022
82dc9bd
Use vipgoci_github_files_affected_by_commit() function.
gudmdharalds Jul 12, 2022
2451ebb
Use vipgoci_github_files_affected_by_commit() function.
gudmdharalds Jul 12, 2022
5f84175
Use vipgoci_github_files_affected_by_commit() function.
gudmdharalds Jul 12, 2022
6ebf236
Use vipgoci_github_files_affected_by_commit() function.
gudmdharalds Jul 12, 2022
c09febe
Remove test as function is removed.
gudmdharalds Jul 12, 2022
1334298
Use VIPGOCI_ISSUE_TYPE_INFO, VIPGOCI_ISSUE_TYPE_WARNING and VIPGOCI_I…
gudmdharalds Jul 12, 2022
802d79a
Use VIPGOCI_ISSUE_TYPE_INFO, VIPGOCI_ISSUE_TYPE_WARNING and VIPGOCI_I…
gudmdharalds Jul 12, 2022
c761127
Rename VIPGOCI_SYNTAX_ERROR_STR to VIPGOCI_LINT_ERROR_STR
gudmdharalds Jul 12, 2022
9088745
Re-arranging order of defines.
gudmdharalds Jul 12, 2022
d43ed67
Merge pull request #281 from Automattic/updates-relating-to-pr273
gudmdharalds Jul 12, 2022
6dc1a3e
Look for addons in root of plugin/theme directory.
gudmdharalds Jul 12, 2022
361d4e6
Sub-directories scan can be disabled via parameter.
gudmdharalds Jul 12, 2022
228d15d
Updated test; both scan for subdirectories and skip.
gudmdharalds Jul 12, 2022
e50a2e5
Updated test; both scan for subdirectories and skip.
gudmdharalds Jul 12, 2022
e4707bd
Report if problematic addon is in list of changed files.
gudmdharalds Jul 12, 2022
7f98720
Add vipgoci_directory_found_in_file_list()
gudmdharalds Jul 12, 2022
c69b6e7
Add test for vipgoci_directory_found_in_file_list()
gudmdharalds Jul 12, 2022
65df6aa
Do not attempt to compare problematic addons against removed files.
gudmdharalds Jul 12, 2022
3e9bb78
Fix WP CS.
gudmdharalds Jul 12, 2022
dba9756
Adjust message slightly.
gudmdharalds Jul 12, 2022
3dfb37c
Rename field for clarity.
gudmdharalds Jul 13, 2022
dca350b
Adding define for WordPress.org-compatible UpdateURIs
gudmdharalds Jul 13, 2022
6057baf
Use function to determine if to wait.
gudmdharalds Jul 13, 2022
883f907
Update test to match function.
gudmdharalds Jul 13, 2022
beffdd8
Adding vipgoci_substring_found_in_array()
gudmdharalds Jul 13, 2022
b1ae7c8
Adding test for vipgoci_string_found_in_substrings_array()
gudmdharalds Jul 13, 2022
0c6e20e
Rename function to vipgoci_string_found_in_substrings_array()
gudmdharalds Jul 13, 2022
e2fc2f7
Rename field for clarity.
gudmdharalds Jul 13, 2022
9224123
Skip when UpdateURI header is not w.org/wordpress.org or is false.
gudmdharalds Jul 13, 2022
7a35c94
Adding Update URI header.
gudmdharalds Jul 13, 2022
42fce8e
Add test for UpdateURI outside of WordPress.org
gudmdharalds Jul 13, 2022
97d1b5d
Simplify test again, test Update URI header in one function. Remove e…
gudmdharalds Jul 13, 2022
4e0ad27
Add entries for new WPScan integration tests.
gudmdharalds Jul 13, 2022
9c3ad17
Adding comment.
gudmdharalds Jul 13, 2022
63cd620
Adding test for vipgoci_wpscan_scan_dirs_altered()
gudmdharalds Jul 13, 2022
1ad38ee
Adding test for vipgoci_wpscan_find_addon_dirs_altered()
gudmdharalds Jul 13, 2022
b261019
Adding test for vipgoci_wpscan_scan_save_for_submission()
gudmdharalds Jul 14, 2022
952a297
Remove variable not needed.
gudmdharalds Jul 14, 2022
4c18e8b
Removing variable not used.
gudmdharalds Jul 14, 2022
0333226
Removing whitespacing.
gudmdharalds Jul 14, 2022
47d64bb
Add test for vipgoci_wpscan_scan_commit()
gudmdharalds Jul 14, 2022
f38bab6
Test certain fields differently.
gudmdharalds Jul 14, 2022
567dc16
Remove extra instance of 'package' from list.
gudmdharalds Jul 14, 2022
bec7bd4
Adding assertations for more fields.
gudmdharalds Jul 14, 2022
f84fcf6
Test also when wpscan-api is disabled.
gudmdharalds Jul 14, 2022
4bc00f8
Adding a few assertations.
gudmdharalds Jul 14, 2022
c6f2071
Adding plugin info to INI file.
gudmdharalds Jul 14, 2022
c79036c
Use information from INI file.
gudmdharalds Jul 14, 2022
4616d7d
Use information from INI file.
gudmdharalds Jul 14, 2022
2948e69
Replacing 'theme-slug' with 'plugin-slug'
gudmdharalds Jul 14, 2022
9117468
Using define for PR label.
gudmdharalds Jul 14, 2022
a505ae9
Adding test for condition when skip-label is associated.
gudmdharalds Jul 14, 2022
6b42573
Apply WP CS, require GitHub token for one test and not the other, add…
gudmdharalds Jul 14, 2022
9cab09e
Use define VIPGOCI_WPSCAN_VULNERABLE.
gudmdharalds Jul 15, 2022
09df129
Add plugin version to INI file.
gudmdharalds Jul 15, 2022
452867c
Using value from INI file; checking if field has correct value.
gudmdharalds Jul 15, 2022
643f25f
Merge branch 'trunk' into add-wpscan-support
gudmdharalds Jul 19, 2022
34c166c
Merge branch 'trunk' into add-wpscan-support
gudmdharalds Jul 19, 2022
bcfc966
Merge branch 'trunk' into add-wpscan-support
gudmdharalds Aug 8, 2022
a5d43ae
Merge branch 'trunk' into add-wpscan-support
gudmdharalds Aug 12, 2022
dd31042
Add support for deciding HTTP protocol version to use.
gudmdharalds Sep 6, 2022
eaa7b7d
Use HTTP 1.1 for WordPress.org API
gudmdharalds Sep 6, 2022
47a3bda
Add --wpscan-api-dry-mode option
gudmdharalds Sep 6, 2022
aa7a83d
Update help message.
gudmdharalds Sep 6, 2022
0ab6adf
Update log debug data. Use $wpscan_api_dry_mode
gudmdharalds Sep 6, 2022
70fb8be
Log to IRC only when WPScan API dry-run mode is enabled.
gudmdharalds Sep 6, 2022
df891e6
Do not auto-approve pull request if WPScan API found issues.
gudmdharalds Sep 6, 2022
46389c8
Rename variable
gudmdharalds Sep 6, 2022
6428aaf
Dry mode disabled by default
gudmdharalds Sep 6, 2022
b255b44
Rename variables to reflect what the function does.
gudmdharalds Sep 7, 2022
cb9fccb
Update logging.
gudmdharalds Sep 7, 2022
e713e83
Updating output due to theme support.
gudmdharalds Sep 8, 2022
880454f
Updating field name.
gudmdharalds Sep 9, 2022
42d099c
Update field name.
gudmdharalds Sep 9, 2022
a616e51
Update field name.
gudmdharalds Sep 9, 2022
709b8cb
Update file keys.
gudmdharalds Sep 9, 2022
1f32f1f
Updating field name, process new key structure, log to IRC.
gudmdharalds Sep 9, 2022
62e83f9
Update field name.
gudmdharalds Sep 9, 2022
c126e08
Updating field names.
gudmdharalds Sep 9, 2022
f45f7aa
Use constant for array key.
gudmdharalds Sep 9, 2022
5c6e257
vipgoci_wpcore_api_determine_slug_and_other_for_addons(): Add support…
gudmdharalds Sep 9, 2022
25db41f
Fixing spacing.
gudmdharalds Sep 9, 2022
6b4e42f
Renaming constant.
gudmdharalds Sep 9, 2022
eaecaee
Renaming constant.
gudmdharalds Sep 9, 2022
1349583
Renaming constant.
gudmdharalds Sep 9, 2022
476d398
Renaming constant.
gudmdharalds Sep 9, 2022
791cb17
Renaming constants.
gudmdharalds Sep 9, 2022
f3e9a4b
Renaming constants.
gudmdharalds Sep 9, 2022
78ee28a
Ensure file/directory exists before adding to results.
gudmdharalds Sep 9, 2022
eb57b20
WP CS fix
gudmdharalds Sep 9, 2022
30cd534
vipgoci_scandir_git_repo(): Support subdirectories
gudmdharalds Sep 12, 2022
8cb606d
vipgoci_scandir_git_repo(): Support subdirectories
gudmdharalds Sep 12, 2022
9550f0e
Update PHPDoc comment
gudmdharalds Sep 12, 2022
9124123
vipgoci_wpcore_misc_scan_directory_for_addons(): Use vipgoci_scandir_…
gudmdharalds Sep 12, 2022
87d83e1
Remove extra space.
gudmdharalds Sep 12, 2022
b7ab239
Add subdirectory parameter, update function names.
gudmdharalds Sep 12, 2022
ff49ce2
Apply WP CS.
gudmdharalds Sep 12, 2022
9895631
Add tests for no subdirectories
gudmdharalds Sep 12, 2022
8d9ab21
Rename functions.
gudmdharalds Sep 12, 2022
bb81cbf
unset() value tested separately, remove from expected results.
gudmdharalds Sep 13, 2022
cc89e3d
Adding theme information in WPScan section.
gudmdharalds Sep 13, 2022
d1ed920
Adding theme checks.
gudmdharalds Sep 13, 2022
77217cd
Add theme check.
gudmdharalds Sep 13, 2022
f52035c
Adding key for plugins/themes altered.
gudmdharalds Sep 13, 2022
e982efe
Adding theme checks.
gudmdharalds Sep 13, 2022
5323576
Add check for theme.
gudmdharalds Sep 14, 2022
5bcbb4c
Rename functions indicating plugin tests.
gudmdharalds Sep 14, 2022
019dada
Adding isset(), in case key/value is missing from API response.
gudmdharalds Sep 14, 2022
f1bb3cd
Add theme check.
gudmdharalds Sep 14, 2022
522a97d
Different severity level for obsolete and vulnerable addons
gudmdharalds Sep 15, 2022
94e2a06
Merge branch 'trunk' into add-wpscan-support
gudmdharalds Sep 15, 2022
434245f
Adding new key/value.
gudmdharalds Sep 15, 2022
477cab4
Updating test, using assertSame()
gudmdharalds Sep 15, 2022
152f82d
Merge branch 'add-wpscan-support' of github.com:Automattic/vip-go-ci …
gudmdharalds Sep 15, 2022
b843b78
Adding key/value for theme.
gudmdharalds Sep 15, 2022
e33b9be
Add checks for theme.
gudmdharalds Sep 15, 2022
ea6e117
Remove extra line.
gudmdharalds Sep 15, 2022
ef76f92
Adding check for updated files in PR.
gudmdharalds Sep 15, 2022
210d138
Adding key/values for WpscanScanFindAddonDirsAlteredTest test.
gudmdharalds Sep 15, 2022
0003b75
Adding test for files removed from PR.
gudmdharalds Sep 15, 2022
86a61d2
Moving test functions around.
gudmdharalds Sep 15, 2022
6f4763c
Updating expected results.
gudmdharalds Sep 15, 2022
c495f23
Updating commit IDs.
gudmdharalds Sep 15, 2022
4e3b018
Adding test for auto-approvals when WPScan is enabled.
gudmdharalds Sep 16, 2022
ddfce51
Updating commit IDs for WPScan tests.
gudmdharalds Sep 16, 2022
1ae9b09
Update test to reflect test-data.
gudmdharalds Sep 16, 2022
4f37d04
Initial README for WPScan API.
gudmdharalds Sep 16, 2022
dec6511
More updates to README for WPScan API.
gudmdharalds Sep 16, 2022
5dde4d6
Clarify text a bit.
gudmdharalds Sep 16, 2022
529a89b
UpdateURI information added.
gudmdharalds Sep 16, 2022
c82bd60
Adding CVSS ranking define.
gudmdharalds Sep 16, 2022
a8d7395
Adding function vipgoci_wpscan_report_format_cvss_score()
gudmdharalds Sep 16, 2022
c51c7d5
Adding test for vipgoci_wpscan_report_format_cvss_score()
gudmdharalds Sep 16, 2022
41d2491
Merge branch 'trunk' into add-wpscan-support
gudmdharalds Sep 21, 2022
784a71b
Appending message to linting string.
gudmdharalds Sep 23, 2022
cf35276
Merge branch 'trunk' into add-wpscan-support
gudmdharalds Sep 23, 2022
b05119d
Alter test to reduce GitHub API calls
gudmdharalds Sep 23, 2022
4c413c7
Test repository data changed
gudmdharalds Sep 23, 2022
0f5ba1b
Calculate installed location in a different way.
gudmdharalds Sep 23, 2022
9c58779
Update test.
gudmdharalds Sep 23, 2022
32d01b8
Installed location format for themes and plugins the same.
gudmdharalds Sep 23, 2022
1d0d936
Add vipgoci_validate_slug()
gudmdharalds Sep 26, 2022
3f3105b
Add test for vipgoci_validate_slug()
gudmdharalds Sep 26, 2022
08f0cde
Validate slugs received from WordPress.org
gudmdharalds Sep 26, 2022
e3eaafe
Escape vulnerability ID in output.
gudmdharalds Sep 26, 2022
a1973a3
Verify ID is escaped.
gudmdharalds Sep 26, 2022
77785aa
Updating test to match function
gudmdharalds Sep 26, 2022
50e99af
Renaming test
gudmdharalds Sep 26, 2022
ab27f04
Rename class.
gudmdharalds Sep 26, 2022
5e5ca70
Temporary ignore sniff
gudmdharalds Sep 26, 2022
dc652ed
Ignore PHPCS sniff temporarily
gudmdharalds Sep 26, 2022
acf91da
Remove wpscan-api-url option
gudmdharalds Sep 26, 2022
5f3ec67
Use constant instead of option for WPScan API URL.
gudmdharalds Sep 26, 2022
9c09e66
Remove wpscan-api-url option
gudmdharalds Sep 26, 2022
ffb92d4
Remove wpscan-api-url option, remove whitespace.
gudmdharalds Sep 26, 2022
dca851b
Use constant instead of wpscan-api-url option.
gudmdharalds Sep 26, 2022
cf1088d
Remove constant as parameter, is used internally in function.
gudmdharalds Sep 26, 2022
0eb6bd0
Add space to string.
gudmdharalds Sep 26, 2022
8622e8c
Updating help message regarding --wpscan-api-report-end-msg and Markdown
gudmdharalds Sep 27, 2022
c1039ca
Add functions to URL escape and Markdown escape input.
gudmdharalds Sep 27, 2022
87e69f1
Test if output is escaped.
gudmdharalds Sep 27, 2022
f20a35f
Test if output is escaped.
gudmdharalds Sep 27, 2022
8c05538
Test if output is escaped.
gudmdharalds Sep 27, 2022
3f7d8b0
Better escaping of output.
gudmdharalds Sep 27, 2022
4b423c6
Field-assignment logic to a function, verify essential fields.
gudmdharalds Sep 27, 2022
266533e
Unset correct variable.
gudmdharalds Sep 27, 2022
ae7b120
Adding helper functions for tests/unit/WpCoreMiscAssignAddonFieldsTes…
gudmdharalds Sep 27, 2022
8a93e42
Adding test for vipgoci_wpcore_misc_assign_addon_fields()
gudmdharalds Sep 27, 2022
17e392d
Move fields around in expected result.
gudmdharalds Sep 27, 2022
8de49e6
Update test to reflect test-data.
gudmdharalds Sep 27, 2022
829396c
Add missing statistics field.
gudmdharalds Sep 27, 2022
d39f401
Fix escaping routine.
gudmdharalds Sep 27, 2022
882c644
Adding test for vipgoci_output_markdown_escape()
gudmdharalds Sep 27, 2022
e167552
Add test for vipgoci_output_sanitize_url()
gudmdharalds Sep 27, 2022
a33f358
Add WPScan API TODO item
gudmdharalds Sep 27, 2022
9b01988
Always log to IRC.
gudmdharalds Sep 28, 2022
cd5e217
Add file required
gudmdharalds Sep 28, 2022
8527dfc
Update message
gudmdharalds Sep 28, 2022
a7b639d
Enabling sniff again
gudmdharalds Sep 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
define( 'VIPGOCI_PHP_VERSION_MINIMUM', '7.3.0' );

/*
* Client-ID for curl-requests, etc.
* Client-ID for HTTP requests.
*/
define( 'VIPGOCI_CLIENT_ID', 'automattic-vip-go-ci' );

/*
* Strings for generic messages.
*/
define( 'VIPGOCI_SYNTAX_ERROR_STR', 'PHP Syntax Errors Found' );
define( 'VIPGOCI_WPSCAN_API_ERROR', 'Automated Addon Security Scanning' );
define( 'VIPGOCI_GITHUB_ERROR_STR', 'GitHub API communication error. Please contact a human.' );

/*
Expand All @@ -35,6 +40,11 @@
define( 'VIPGOCI_GITHUB_BASE_URL', 'https://api.github.com' );
}

/*
* Defines for various sizes, such as KB.
*/
define( 'VIPGOCI_KB_IN_BYTES', 1024 );

/*
* Timeout constant for HTTP APIs.
*/
Expand Down Expand Up @@ -158,15 +168,21 @@
* arguments passed to the program (e.g., --phpcs)
* -- altering these is not recommended.
*/

define( 'VIPGOCI_STATS_PHPCS', 'phpcs' );
define( 'VIPGOCI_STATS_LINT', 'lint' );
define( 'VIPGOCI_STATS_HASHES_API', 'hashes-api' );
define( 'VIPGOCI_STATS_WPSCAN_API', 'wpscan-api' );

/*
* Define auto-approval types
* Define error/warning/info constants.
*/
define( 'VIPGOCI_ISSUE_TYPE_INFO', 'info' );
define( 'VIPGOCI_ISSUE_TYPE_WARNING', 'warning' );
define( 'VIPGOCI_ISSUE_TYPE_ERROR', 'error' );

/*
* Define auto-approval types
*/
define( 'VIPGOCI_APPROVAL_AUTOAPPROVE', 'auto-approval' );
define( 'VIPGOCI_APPROVAL_HASHES_API', 'hashes-api' );

Expand Down Expand Up @@ -228,3 +244,22 @@
);

define( 'VIPGOCI_VALIDATION_MAXIMUM_DETAIL_MSG', 'Note that the above file(s) were not analyzed due to their length.' );

/*
* Defines for WPScan API support.
*/
define( 'VIPGOCI_WPSCAN_PLUGIN', 'vipgoci-wpscan-plugin' );
define( 'VIPGOCI_WPSCAN_THEME', 'vipgoci-wpscan-theme' );
define( 'VIPGOCI_WPSCAN_BASE_URL', 'https://wpscan.com' );
define( 'VIPGOCI_WPSCAN_API_BASE_URL', VIPGOCI_WPSCAN_BASE_URL . '/api/v3' );

define( 'VIPGOCI_WPSCAN_VULNERABLE', 'vulnerable' );
define( 'VIPGOCI_WPSCAN_OBSOLETE', 'obsolete' );

define( 'VIPGOCI_WPSCAN_SEVERITY_UNKNOWN', -1 );
define( 'VIPGOCI_WPSCAN_SEVERITY_NONE', 0.0 );
define( 'VIPGOCI_WPSCAN_SEVERITY_LOW', 3.9 ); // 0.1-3.9.
define( 'VIPGOCI_WPSCAN_SEVERITY_MEDIUM', 6.9 ); // 4.0-6.9.
define( 'VIPGOCI_WPSCAN_SEVERITY_HIGH', 8.9 ); // 7.0-8.9.
define( 'VIPGOCI_WPSCAN_SEVERITY_CRITICAL', 10.0 ); // 9.0-10.

125 changes: 125 additions & 0 deletions github-misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,128 @@ function vipgoci_github_prs_urls_get(

return $prs_urls;
}

/**
gudmdharalds marked this conversation as resolved.
Show resolved Hide resolved
* Construct array of files affected -- altered, added, deleted -- by
* each pull request implicated by the commit. Will also include list
* of all files affected.
*
* @param array $options Options array for the program.
* @param string $commit_id Commit-ID of current commit.
* @param array $commit_skipped_files Information about skipped files (reference).
* @param array $skip_folders Directories not to scan.
*
* @return array Returns associative array with key as pull request number and value as array of affected files. Includes special key 'all' which includes all files altered by all pull requests. Example:
* Array(
* [all] => Array(
* [0] => folder1/test.php
* [1] => folder2/test2.php
* [2] => testing/file.php
* ),
* [17] => Array(
* [0] => folder1/test.php
* [1] => testing/file.php
* ),
* [20] => Array(
* [0] => folder1/test.php
* [1] => folder2/test2.php
* )
* )
*/
function vipgoci_github_files_affected_by_commit(
gudmdharalds marked this conversation as resolved.
Show resolved Hide resolved
gudmdharalds marked this conversation as resolved.
Show resolved Hide resolved
array $options,
string $commit_id,
array &$commit_skipped_files,
array $skip_folders
) :array {
vipgoci_log(
'Fetching list of all files affected by each pull request ' .
'implicated by the commit',
array(
'repo_owner' => $options['repo-owner'],
'repo_name' => $options['repo-name'],
'commit_id' => $options['commit'],
)
);

// Fetch list of all pull requests which the commit is a part of.
$prs_implicated = vipgoci_github_prs_implicated(
$options['repo-owner'],
$options['repo-name'],
$commit_id,
$options['token'],
$options['branches-ignore'],
$options['skip-draft-prs']
);

$pr_item_files_changed = array(
'all' => array(),
);

foreach ( $prs_implicated as $pr_item ) {
/*
* Make sure that the PR is defined in the array.
*/
if ( ! isset( $pr_item_files_changed[ $pr_item->number ] ) ) {
$pr_item_files_changed[ $pr_item->number ] = array();
}

/*
* Get list of all files changed
* in this pull request.
*/
$pr_item_files_tmp = vipgoci_git_diffs_fetch(
$options['local-git-repo'],
$options['repo-owner'],
$options['repo-name'],
$options['token'],
$pr_item->base->sha,
$options['commit'],
false, // Exclude renamed files.
false, // Exclude removed files.
false, // Exclude permission changes.
array(
'file_extensions' => array( 'php' ),
'skip_folders' => $skip_folders,
)
);

foreach (
array_keys( $pr_item_files_tmp['files'] ) as
$pr_item_file_name
) {
/*
* Check for too long file.
*/
if (
( isset(
$commit_skipped_files[ $pr_item->number ]['issues'][ VIPGOCI_VALIDATION_MAXIMUM_LINES ]
) )
&&
( true === in_array(
$pr_item_file_name,
$commit_skipped_files[ $pr_item->number ]['issues'][ VIPGOCI_VALIDATION_MAXIMUM_LINES ],
true
) )
) {
continue;
}

/*
* Add file to arrays, if not already there.
*/
vipgoci_array_push_uniquely(
$pr_item_files_changed['all'],
$pr_item_file_name
);

vipgoci_array_push_uniquely(
$pr_item_files_changed[ $pr_item->number ],
$pr_item_file_name
);
}
}

return $pr_item_files_changed;
}

79 changes: 64 additions & 15 deletions http-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,15 @@ function vipgoci_http_api_fetch_url(
$http_api_auth_header,
)
);
} elseif ( isset( $http_api_token['wpscan_token'] ) ) {
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
'Authorization: Token token=' .
$http_api_token['wpscan_token'],
)
);
}
}

Expand Down Expand Up @@ -720,21 +729,27 @@ function vipgoci_http_api_fetch_url(
* Note that the '$http_delete' parameter will determine
* if a POST or DELETE request will be sent.
*
* @param string $http_api_url HTTP request URL.
* @param array $http_api_postfields HTTP request fields.
* @param string $http_api_token Access token to use.
* @param bool $http_delete If to perform HTTP DELETE instead of POST.
* @param string $http_api_url HTTP request URL.
* @param array $http_api_postfields HTTP request postfields.
* @param null|string $http_api_token Access token to use as string, null to skip.
* @param bool $http_delete When true, performs HTTP DELETE instead of POST.
* @param bool $json_encode If true, will JSON encode $http_api_postfields using json_encode()
* before sending request, else uses http_build_query() to
* generate URL-encoded query-string from $http_api_postfields.
* @param string $http_content_type The HTTP Content-Type header value to use. 'application/json' is the default.
*
* @return int Zero (0) on success, -1 on failure. Failures will be logged.
* @return string|int Request body as string on success, -1 on failure. Failures will be logged.
*
* @codeCoverageIgnore
*/
function vipgoci_http_api_post_url(
string $http_api_url,
array $http_api_postfields,
string $http_api_token,
bool $http_delete = false
) :null|int {
null|string $http_api_token,
bool $http_delete = false,
bool $json_encode = true,
string $http_content_type = 'application/json'
) :string|int {
/*
* Actually send a request to HTTP API -- make sure
* to retry if something fails.
Expand Down Expand Up @@ -796,10 +811,21 @@ function vipgoci_http_api_post_url(
);
}

// Encode postfields as JSON if requested, else generate URL-encoded query string.
if ( true === $json_encode ) {
$tmp_postfields = json_encode(
$http_api_postfields
);
} else {
$tmp_postfields = http_build_query(
$http_api_postfields
);
}

curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
json_encode( $http_api_postfields )
$tmp_postfields
);

curl_setopt(
Expand All @@ -808,11 +834,29 @@ function vipgoci_http_api_post_url(
'vipgoci_curl_headers'
);

curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array( 'Authorization: token ' . $http_api_token )
);
// Construct HTTP headers to send with the request.
$tmp_http_headers_arr = array();

if (
( is_string( $http_api_token ) ) &&
( strlen( $http_api_token ) > 0 )
) {
$tmp_http_headers_arr[] = 'Authorization: token ' . $http_api_token;
}

if ( strlen( $http_content_type ) > 0 ) {
$tmp_http_headers_arr[] = 'Content-Type: ' . $http_content_type;
}

if ( ! empty( $tmp_http_headers_arr ) ) {
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
$tmp_http_headers_arr
);
}

unset( $tmp_http_headers_arr );

vipgoci_curl_set_security_options(
$ch
Expand Down Expand Up @@ -922,6 +966,7 @@ function vipgoci_http_api_post_url(
}
}

// On failure, log message.
if ( -1 === $ret_val ) {
vipgoci_log(
( false === $resp_data ?
Expand Down Expand Up @@ -973,7 +1018,11 @@ function vipgoci_http_api_post_url(
( $retry_cnt++ < $retry_max )
);

return $ret_val;
if ( 0 === $ret_val ) {
return $resp_data;
} else {
return $ret_val;
}
}

/**
Expand Down
Loading