diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..f90230b --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,12 @@ +## Problem + +- *Description of why you made this PR, what is its purpose* + +## Solution + +- *And how do you relevantly fix that problem* + +## PR checklist + +- [ ] PR finished and ready to be reviewed + \ No newline at end of file diff --git a/.github/autoblack.yml b/.github/autoblack.yml new file mode 100644 index 0000000..761222b --- /dev/null +++ b/.github/autoblack.yml @@ -0,0 +1,35 @@ +name: Check / auto apply Black +on: + push: + branches: + - master +jobs: + black: + name: Check / auto apply black + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check files using the black formatter + uses: psf/black@stable + id: black + with: + options: "." + continue-on-error: true + - shell: pwsh + id: check_files_changed + run: | + # Diff HEAD with the previous commit + $diff = git diff + $HasDiff = $diff.Length -gt 0 + Write-Host "::set-output name=files_changed::$HasDiff" + - name: Create Pull Request + if: steps.check_files_changed.outputs.files_changed == 'true' + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + title: "Format Python code with Black" + commit-message: ":art: Format Python code with Black" + body: | + This pull request uses the [psf/black](https://github.com/psf/black) formatter. + base: ${{ github.head_ref }} # Creates pull request onto pull request or commit branch + branch: actions/black diff --git a/package_linter.py b/package_linter.py index c1d6ea0..fe345b9 100755 --- a/package_linter.py +++ b/package_linter.py @@ -1447,8 +1447,8 @@ class Configurations(TestSuite): cmd = 'grep -q -IhEro "location ~ __PATH__" %s' % (app.path + "/conf/" + filename) - if os.system(cmd) != 0: - yield Info( + if os.system(cmd) == 0: + yield Warning( "When using regexp in the nginx location field (location ~ __PATH__), start the path with ^ (location ~ ^__PATH__)." ) @@ -1565,30 +1565,32 @@ class Configurations(TestSuite): @test() def bind_public_ip(self): app = self.app - for filename in ( - os.listdir(app.path + "/conf") if os.path.exists(app.path + "/conf") else [] + for path, subdirs, files in ( + os.walk(app.path + "/conf") if os.path.exists(app.path + "/conf") else [] ): - try: - content = open(app.path + "/conf/" + filename).read() - except Exception as e: - yield Warning("Can't open/read %s: %s" % (filename, e)) - return + for filename in files: + try: + content = open(os.path.join(path, filename)).read() + except Exception as e: + yield Warning("Can't open/read %s: %s" % (os.path.join(path, filename), e)) + return for number, line in enumerate(content.split("\n"), 1): comment = ("#", "//", ";", "/**", "*") - if ( - ( "0.0.0.0" in line or "::" in line ) - and not line.strip().startswith(comment) - ): - for ip in re.split("[ \t,='\"(){}\[\]]", line): - if ip == "::" or ip.startswith("0.0.0.0"): - yield Info( - f"{filename}:{number}: Binding to '0.0.0.0' or '::' can result " - "in a security issue as the reverse proxy and the SSO can be " - "bypassed by knowing a public IP (typically an IPv6) and the " - "app port. lease be sure that this behavior is intentional. " - "Maybe use '127.0.0.1' or '::1' instead." - ) + if ( + ( "0.0.0.0" in line or "::" in line ) + and not line.strip().startswith(comment) + ): + for ip in re.split("[ \t,='\"(){}\[\]]", line): + if ip == "::" or ip.startswith("0.0.0.0"): + yield Info( + f"{os.path.relpath(path, app.path)}/{filename}:{number}: " + "Binding to '0.0.0.0' or '::' can result in a security issue " + "as the reverse proxy and the SSO can be bypassed by knowing " + "a public IP (typically an IPv6) and the app port. " + "Please be sure that this behavior is intentional. " + "Maybe use '127.0.0.1' or '::1' instead." + ) ############################################# # __ __ _ __ _ #