├── .github └── workflows │ ├── codespell.yml │ ├── release.yml │ └── test.yml ├── .rubocop.yml ├── CHANGELOG.md ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── controls └── php_conf.rb ├── inspec.yml ├── libraries └── php.rb └── renovate.json /.github/workflows/codespell.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Codespell - Spellcheck 3 | 4 | on: # yamllint disable-line rule:truthy 5 | push: 6 | branches: [master] 7 | pull_request: 8 | branches: [master] 9 | 10 | jobs: 11 | codespell: 12 | uses: "dev-sec/.github/.github/workflows/codespell.yml@main" 13 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: New release 3 | 4 | on: # yamllint disable-line rule:truthy 5 | workflow_dispatch: 6 | push: 7 | branches: 8 | - master 9 | 10 | jobs: 11 | generate_changelog: 12 | uses: dev-sec/.github/.github/workflows/baseline-release.yml@main 13 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | schedule: 9 | - cron: '0 6 * * *' 10 | 11 | jobs: 12 | test: 13 | uses: dev-sec/.github/.github/workflows/baseline-test.yml@main 14 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | --- 2 | AllCops: 3 | Exclude: 4 | - vendor/**/* 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [1.0.5](https://github.com/dev-sec/php-baseline/tree/1.0.5) (2023-05-02) 4 | 5 | [Full Changelog](https://github.com/dev-sec/php-baseline/compare/1.0.4...1.0.5) 6 | 7 | **Implemented enhancements:** 8 | 9 | - use centralised issue templates and workflows [\#18](https://github.com/dev-sec/php-baseline/pull/18) ([schurzi](https://github.com/schurzi)) 10 | 11 | **Merged pull requests:** 12 | 13 | - add spellchecking with codespell [\#20](https://github.com/dev-sec/php-baseline/pull/20) ([schurzi](https://github.com/schurzi)) 14 | - Configure Renovate [\#19](https://github.com/dev-sec/php-baseline/pull/19) ([renovate[bot]](https://github.com/apps/renovate)) 15 | - Change linting to Cookstyle [\#17](https://github.com/dev-sec/php-baseline/pull/17) ([schurzi](https://github.com/schurzi)) 16 | 17 | ## [1.0.4](https://github.com/dev-sec/php-baseline/tree/1.0.4) (2022-01-12) 18 | 19 | [Full Changelog](https://github.com/dev-sec/php-baseline/compare/1.0.3...1.0.4) 20 | 21 | **Merged pull requests:** 22 | 23 | - Minimum requirements [\#16](https://github.com/dev-sec/php-baseline/pull/16) ([micheelengronne](https://github.com/micheelengronne)) 24 | - fix rubocop error for Rakefile [\#14](https://github.com/dev-sec/php-baseline/pull/14) ([schurzi](https://github.com/schurzi)) 25 | - add dependency to chef-config for CI [\#13](https://github.com/dev-sec/php-baseline/pull/13) ([schurzi](https://github.com/schurzi)) 26 | - use version tag for changelog action [\#12](https://github.com/dev-sec/php-baseline/pull/12) ([schurzi](https://github.com/schurzi)) 27 | - Fix lint [\#11](https://github.com/dev-sec/php-baseline/pull/11) ([schurzi](https://github.com/schurzi)) 28 | - GitHub action [\#10](https://github.com/dev-sec/php-baseline/pull/10) ([rndmh3ro](https://github.com/rndmh3ro)) 29 | 30 | ## [1.0.3](https://github.com/dev-sec/php-baseline/tree/1.0.3) (2020-07-23) 31 | 32 | [Full Changelog](https://github.com/dev-sec/php-baseline/compare/1.0.2...1.0.3) 33 | 34 | **Merged pull requests:** 35 | 36 | - The release draft references the correct SHA [\#9](https://github.com/dev-sec/php-baseline/pull/9) ([micheelengronne](https://github.com/micheelengronne)) 37 | 38 | ## [1.0.2](https://github.com/dev-sec/php-baseline/tree/1.0.2) (2020-06-18) 39 | 40 | [Full Changelog](https://github.com/dev-sec/php-baseline/compare/1.0.1...1.0.2) 41 | 42 | **Merged pull requests:** 43 | 44 | - github actions release [\#8](https://github.com/dev-sec/php-baseline/pull/8) ([micheelengronne](https://github.com/micheelengronne)) 45 | - Update issue templates [\#7](https://github.com/dev-sec/php-baseline/pull/7) ([rndmh3ro](https://github.com/rndmh3ro)) 46 | - use recommended spdx license identifier [\#6](https://github.com/dev-sec/php-baseline/pull/6) ([chris-rock](https://github.com/chris-rock)) 47 | - spell correction in disable\_functions [\#5](https://github.com/dev-sec/php-baseline/pull/5) ([TLoebner](https://github.com/TLoebner)) 48 | 49 | ## [1.0.1](https://github.com/dev-sec/php-baseline/tree/1.0.1) (2017-05-08) 50 | 51 | [Full Changelog](https://github.com/dev-sec/php-baseline/compare/1.0.0...1.0.1) 52 | 53 | **Merged pull requests:** 54 | 55 | - update metadata [\#4](https://github.com/dev-sec/php-baseline/pull/4) ([chris-rock](https://github.com/chris-rock)) 56 | - restrict ruby testing to version 2.3.3 and update gemfile [\#3](https://github.com/dev-sec/php-baseline/pull/3) ([atomic111](https://github.com/atomic111)) 57 | 58 | ## [1.0.0](https://github.com/dev-sec/php-baseline/tree/1.0.0) (2016-12-22) 59 | 60 | [Full Changelog](https://github.com/dev-sec/php-baseline/compare/0.1.0...1.0.0) 61 | 62 | **Merged pull requests:** 63 | 64 | - migrate from Serverspec to InSpec [\#2](https://github.com/dev-sec/php-baseline/pull/2) ([chris-rock](https://github.com/chris-rock)) 65 | 66 | ## [0.1.0](https://github.com/dev-sec/php-baseline/tree/0.1.0) (2016-11-09) 67 | 68 | [Full Changelog](https://github.com/dev-sec/php-baseline/compare/f0de42996b3299ac0e9dc2821c693612f6134cbb...0.1.0) 69 | 70 | **Merged pull requests:** 71 | 72 | - fix typo in license header [\#1](https://github.com/dev-sec/php-baseline/pull/1) ([chris-rock](https://github.com/chris-rock)) 73 | 74 | 75 | 76 | \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* 77 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gem 'cookstyle' 6 | gem 'highline' 7 | gem 'rack' 8 | gem 'rake' 9 | gem 'rubocop' 10 | 11 | group :tools do 12 | gem 'github_changelog_generator' 13 | gem 'pry-coolline' 14 | end 15 | 16 | source 'https://packagecloud.io/cinc-project/stable' do 17 | gem 'chef-config' 18 | gem 'cinc-auditor-bin' 19 | end 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DevSec PHP Baseline 2 | =================== 3 | 4 | This is currently in development! Any feedback or Pull Request is welcome. 5 | 6 | ## Standalone Usage 7 | 8 | This Compliance Profile requires [InSpec](https://github.com/chef/inspec) for execution: 9 | 10 | ``` 11 | $ git clone https://github.com/dev-sec/php-baseline 12 | $ inspec exec php-baseline 13 | ``` 14 | 15 | You can also execute the profile directly from Github: 16 | 17 | ``` 18 | $ inspec exec https://github.com/dev-sec/php-baseline 19 | ``` 20 | 21 | ## License and Author 22 | 23 | * Author:: Dominik Richter 24 | * Author:: Christoph Hartmann 25 | 26 | * Copyright 2015-2016, The Hardening Framework Team 27 | 28 | Licensed under the Apache License, Version 2.0 (the "License"); 29 | you may not use this file except in compliance with the License. 30 | You may obtain a copy of the License at 31 | 32 | http://www.apache.org/licenses/LICENSE-2.0 33 | 34 | Unless required by applicable law or agreed to in writing, software 35 | distributed under the License is distributed on an "AS IS" BASIS, 36 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 37 | See the License for the specific language governing permissions and 38 | limitations under the License. 39 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'cookstyle' 4 | require 'rake/testtask' 5 | require 'rubocop/rake_task' 6 | 7 | # Rubocop 8 | desc 'Run Rubocop lint checks' 9 | task :rubocop do 10 | RuboCop::RakeTask.new 11 | end 12 | 13 | RuboCop::RakeTask.new(:cookstyle) do |task| 14 | task.options << '--display-cop-names' 15 | end 16 | 17 | # lint the project 18 | desc 'Run robocop linter' 19 | task lint: [:rubocop] 20 | 21 | # run tests 22 | task default: [:lint, 'test:check'] 23 | 24 | namespace :test do 25 | # run inspec check to verify that the profile is properly configured 26 | task :check do 27 | require 'inspec' 28 | puts "Checking profile with InSpec Version: #{Inspec::VERSION}" 29 | profile = Inspec::Profile.for_target('.', backend: Inspec::Backend.create(Inspec::Config.mock)) 30 | pp profile.check 31 | end 32 | end 33 | 34 | task :changelog do 35 | # Automatically generate a changelog for this project. Only loaded if 36 | # the necessary gem is installed. By default its picking up the version from 37 | # inspec.yml. You can override that behavior with `rake changelog to=1.2.0` 38 | 39 | require 'yaml' 40 | metadata = YAML.load_file('inspec.yml') 41 | v = ENV['to'] || metadata['version'] 42 | puts " * Generating changelog for version #{v}" 43 | require 'github_changelog_generator/task' 44 | GitHubChangelogGenerator::RakeTask.new :changelog do |config| 45 | config.future_release = v 46 | config.user = 'dev-sec' 47 | config.project = 'php-baseline' 48 | end 49 | Rake::Task[:changelog].execute 50 | rescue LoadError 51 | puts '>>>>> GitHub Changelog Generator not loaded, omitting tasks' 52 | end 53 | -------------------------------------------------------------------------------- /controls/php_conf.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # 4 | # Copyright:: 2015, Dominik Richter 5 | # Copyright:: 2016, Christoph Hartmann 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | title 'PHP config parameters' 21 | 22 | # Some things we don't do: 23 | # * safe_mode 24 | # reason: deprecated 25 | # see: http://php.net/manual/de/features.safe-mode.php 26 | 27 | # Base configuration 28 | describe php_config('open_basedir') do 29 | its('value') { should eq '/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/' } 30 | end 31 | 32 | # Time / Memory Quota 33 | 34 | describe php_config('max_execution_time') do 35 | its('value') { should cmp 30 } 36 | end 37 | 38 | describe php_config('max_input_nesting_level') do 39 | its('value') { should cmp 64 } 40 | end 41 | 42 | describe php_config('memory_limit') do 43 | its('value') { should eq '128M' } 44 | end 45 | 46 | describe php_config('post_max_size') do 47 | its('value') { should eq '8M' } 48 | end 49 | 50 | # PHP Capabilities 51 | 52 | # TODO: do we have a recommended minimum-set? 53 | describe php_config('disable_functions') do 54 | its('value') { should eq 'php_uname, getmyuid, getmypid, passthru, leak, listen, diskfreespace, tmpfile, link, ignore_user_abort, shell_exec, dl, set_time_limit, exec, system, highlight_file, source, show_source, fpaththru, virtual, posix_ctermid, posix_getcwd, posix_getegid, posix_geteuid, posix_getgid, posix_getgrgid, posix_getgrnam, posix_getgroups, posix_getlogin, posix_getpgid, posix_getpgrp, posix_getpid, posix, _getppid, posix_getpwnam, posix_getpwuid, posix_getrlimit, posix_getsid, posix_getuid, posix_isatty, posix_kill, posix_mkfifo, posix_setegid, posix_seteuid, posix_setgid, posix_setpgid, posix_setsid, posix_setuid, posix_times, posix_ttyname, posix_uname, proc_open, proc_close, proc_get_status, proc_nice, proc_terminate, phpinfo' } 55 | end 56 | 57 | # TODO: do we have a recommended minimum-set? 58 | describe php_config('disable_classes') do 59 | its('value') { should cmp '...' } 60 | end 61 | 62 | describe php_config('register_globals') do 63 | its('value') { should cmp 'Off' } 64 | end 65 | 66 | describe php_config('expose_php') do 67 | its('value') { should cmp 'Off' } 68 | end 69 | 70 | describe php_config('enable_dl') do 71 | its('value') { should cmp 'Off' } 72 | end 73 | 74 | describe php_config('default_charset') do 75 | its('value') { should cmp 'utf-8' } 76 | end 77 | 78 | describe php_config('default_mimetype') do 79 | its('value') { should cmp 'text/html' } 80 | end 81 | 82 | # removed as of PHP5.4, so... 83 | # remove these test? 84 | describe php_config('magic_quotes_gpc') do 85 | its('value') { should eq nil } 86 | end 87 | describe php_config('magic_quotes_sybase') do 88 | its('value') { should eq nil } 89 | end 90 | 91 | # # removed // how to test this? 92 | # describe php_config('magic_quotes_runtime') do 93 | # its('value') { should eq 'Off'} 94 | # end 95 | 96 | # Upload / Open 97 | 98 | describe php_config('allow_url_fopen') do 99 | its('value') { should cmp 'Off' } 100 | end 101 | 102 | describe php_config('allow_url_include') do 103 | its('value') { should cmp 'Off' } 104 | end 105 | 106 | describe php_config('file_uploads') do 107 | its('value') { should cmp 'Off' } 108 | end 109 | 110 | # Alternative: restrict upload maximum to prevent 111 | # system overload: 112 | # upload_tmp_dir = /var/php_tmp 113 | # upload_max_filezize = 10M 114 | 115 | # Log // Information Disclosure 116 | 117 | describe php_config('display_errors') do 118 | its('value') { should cmp 'Off' } 119 | end 120 | 121 | describe php_config('display_startup_errors') do 122 | its('value') { should cmp 'Off' } 123 | end 124 | 125 | describe php_config('log_errors') do 126 | its('value') { should cmp 'On' } 127 | end 128 | 129 | # Session Handling 130 | describe php_config('session.save_path') do 131 | its('value') { should cmp '/var/lib/php' } 132 | end 133 | 134 | describe php_config('session.cookie_httponly') do 135 | its('value') { should cmp 1 } 136 | end 137 | 138 | # Mail 139 | 140 | describe php_config('mail.add_x_header') do 141 | its('value') { should cmp 'Off' } 142 | end 143 | -------------------------------------------------------------------------------- /inspec.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: php-baseline 3 | title: DevSec PHP Baseline 4 | maintainer: DevSec Hardening Framework Team 5 | copyright: DevSec Hardening Framework Team 6 | copyright_email: hello@dev-sec.io 7 | license: Apache-2.0 8 | inspec_version: '>= 4.6.3' 9 | summary: Test-suite for best-practice php hardening 10 | version: 1.0.5 11 | supports: 12 | - os-family: unix 13 | -------------------------------------------------------------------------------- /libraries/php.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # 4 | # Copyright:: 2016, Christoph Hartmann 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | class PHP < Inspec.resource(1) 20 | name 'php' 21 | 22 | example " 23 | describe php.config('max_execution_time') do 24 | it { should cmp 0 } 25 | end 26 | 27 | describe php.extension('tillext') do 28 | it { should_not be_loaded } 29 | end 30 | 31 | describe php.extension('session') do 32 | it { should be_loaded } 33 | end 34 | " 35 | 36 | def initialize(options = {}) 37 | super() 38 | @options = options 39 | end 40 | 41 | # returns php runtime information 42 | def info 43 | inspec.command("#{_php_executable} -i") 44 | end 45 | 46 | def config(param) 47 | cmd = inspec.command("#{_php_executable} -r 'echo get_cfg_var( \"#{param}\" );'") 48 | cmd.stdout 49 | end 50 | 51 | def extension(extension) 52 | ext = Class.new do 53 | def initialize(parent, extension) 54 | super 55 | @parent = parent 56 | @extension = extension 57 | end 58 | 59 | def loaded? 60 | cmd = @parent._run("#{@parent._php_executable} --ri '#{@extension}'") 61 | return true if cmd.exit_status.zero? 62 | 63 | false 64 | end 65 | 66 | def to_s 67 | "PHP Extension #{@extension}" 68 | end 69 | end 70 | ext.new(self, extension) 71 | end 72 | 73 | # internal methods 74 | 75 | def _php_executable 76 | cmd = 'php' 77 | cmd += " -c #{@options[:ini]}" if !@options.nil? && @options.key?(:ini) 78 | cmd 79 | end 80 | 81 | def _run(cmd) 82 | inspec.command(cmd) 83 | end 84 | end 85 | 86 | # Deprecated Serverspec resource 87 | class PHPConfig < PHP 88 | name 'php_config' 89 | 90 | example " 91 | describe php_config('default_mimetype') do 92 | its('value') { should eq 'text/html' } 93 | end 94 | " 95 | 96 | def initialize(param) 97 | super() 98 | warn '[DEPRECATION] `php_config(param)` is deprecated. Please use `php.config(param)` instead.' 99 | @param = param 100 | end 101 | 102 | def value 103 | config(@param) 104 | end 105 | 106 | def to_s 107 | "PHP Config #{@param}" 108 | end 109 | end 110 | 111 | # Deprecated Serverspec resource 112 | class PHPExtension < PHP 113 | name 'php_extension' 114 | 115 | example " 116 | describe php_extension('tillext') do 117 | it { should_not be_loaded } 118 | end 119 | 120 | describe php_extension('session') do 121 | it { should be_loaded } 122 | end 123 | " 124 | 125 | def initialize(extension) 126 | super 127 | warn '[DEPRECATION] `php_extension(ext)` is deprecated. Please use `php.extension(ext)` instead.' 128 | @extension = extension 129 | end 130 | 131 | def loaded? 132 | extension(@extension).loaded? 133 | end 134 | 135 | def to_s 136 | "PHP Extension #{@extension}" 137 | end 138 | end 139 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:base", 5 | ":gitSignOff" 6 | ], 7 | "dependencyDashboard": true, 8 | "dependencyDashboardAutoclose": true, 9 | "packageRules": [ 10 | { 11 | "matchUpdateTypes": ["patch", "minor"], 12 | "automerge": true 13 | } 14 | ] 15 | } 16 | --------------------------------------------------------------------------------