Skip to content

Commit

Permalink
Bump eslint from 9.4.0 to 9.5.0, cspell from 8.8.3 to 8.8.4, and mark…
Browse files Browse the repository at this point in the history
…downlint-cli from 0.40.0 to 0.41.0
  • Loading branch information
collinmcneese committed Jun 19, 2024
1 parent ab6b563 commit 518c315
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 49 deletions.
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

18 changes: 0 additions & 18 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 github.com/collinmcneese
Copyright (c) github.com/collinmcneese

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion __test__/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function ci-run {

cd "$(dirname "$0")/.."

ci-run npx eslint --ignore-path .eslintignore .
ci-run npx eslint
ci-run npx cspell *.js *.md
ci-run npx markdownlint-cli -c markdownlint.yml *.md
ci-run npx jest
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ inputs:
description: 'Location to an allow list of target URL entries.'
required: false
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'
20 changes: 20 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const js = require('@eslint/js');

module.exports = [
{
ignores: ['__test__/**/*', 'dist/**/*', 'node_modules/**/*'],
},
{
languageOptions: {
ecmaVersion: 2018,
sourceType: 'commonjs',
},
},
js.configs.recommended,
{
rules: {
semi: "error",
"prefer-const": "error"
}
}
];
14 changes: 1 addition & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
},
"homepage": "https://github.com/collinmcneese/github-actions-forwarder#readme",
"devDependencies": {
"@eslint/js": "^9.5.0",
"cspell": "^8.8.4",
"eslint": "^9.5.0",
"eslint-config-strongloop": "^2.1.0",
"jest": "^29.7.0",
"markdownlint-cli": "^0.41.0"
},
Expand Down
19 changes: 10 additions & 9 deletions src/forwarder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
const request = require('request');
const crypto = require('crypto');
const URL = require('url').URL;
const console = require('console');

// Function to validate that passed URL is a valid URL
function validateUrl(urlString) {
try {
new URL(urlString); // eslint-disable-line no-new
new URL(urlString);
return true;
} catch (err) {
throw new Error(`Invalid URL: ${urlString} \n ${err}`);
Expand Down Expand Up @@ -47,17 +48,17 @@ async function fetchAllowListSource(allowListSource) {

// Function to validate that passed target URL is in the passed allowList array via pattern matching
function validateAllowList(targetUrl, allowList) {
let targetUrlObj = new URL(targetUrl);
const targetUrlObj = new URL(targetUrl);

for (let i = 0; i < allowList.length; i++) {
let allowListUrlObj = new URL(allowList[i]);
const allowListUrlObj = new URL(allowList[i]);

if (targetUrlObj.hostname === allowListUrlObj.hostname) {
return true;
}
// support for wildcard partial matching in allowList
if (allowListUrlObj.hostname.startsWith('*')) {
let wildcard = allowListUrlObj.hostname.replace('*', '');
const wildcard = allowListUrlObj.hostname.replace('*', '');

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This replaces only the first occurrence of '*'.
if (targetUrlObj.hostname.endsWith(wildcard)) {
return true;
}
Expand All @@ -79,11 +80,11 @@ function getWebhookSignature(payload, secret, algorithm) {

// Function to return Request object with passed context, targetUrl and webhookSecret
function getRequestOptions(context, targetUrl, webhookSecret) {
let payloadJson = JSON.stringify(context.payload, undefined, 2);
const payloadJson = JSON.stringify(context.payload, undefined, 2);

// Build request options
// Include the signature in the headers, if a webhookSecret was provided
let options = {
const options = {
url: targetUrl,
method: 'POST',
headers: {
Expand All @@ -110,7 +111,7 @@ async function forwarder({context, targetUrl, webhookSecret, allowListSource}) {

// If allowListSource is provided, fetch the allowList and validate that targetUrl is in the allowList
if (allowListSource) {
let allowList = await fetchAllowListSource(allowListSource);
const allowList = await fetchAllowListSource(allowListSource);

if (!validateAllowList(targetUrl, allowList)) {
throw new Error(`targetUrl: ${targetUrl} is not in allowListSource: ${allowListSource}`);
Expand All @@ -120,11 +121,11 @@ async function forwarder({context, targetUrl, webhookSecret, allowListSource}) {
}

// Build request options
let options = getRequestOptions(context, targetUrl, webhookSecret);
const options = getRequestOptions(context, targetUrl, webhookSecret);

// Send the request
return new Promise((resolve, reject) => {
request(options, (error, response, body) => {
request(options, (error, response) => {
if (error) {
reject(error);
} else if (response.statusCode < 200 || response.statusCode >= 300) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ forwarder({
webhookSecret: webhookSecret,
allowListSource: allowListSource,
}).then((result) => {
console.log(result);
core.info(result);

core.summary
.addRaw(result)
Expand Down

0 comments on commit 518c315

Please sign in to comment.