From ce23dcb32c9a6053aba215a0f47c5e1bc307817a Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Fri, 25 Feb 2022 10:38:29 +0100 Subject: [PATCH] fix: return 410 for api/github (#45250) --- api-server/src/server/boot/randomAPIs.js | 68 ++++-------------------- config/misc.js | 2 - 2 files changed, 10 insertions(+), 60 deletions(-) diff --git a/api-server/src/server/boot/randomAPIs.js b/api-server/src/server/boot/randomAPIs.js index 28591934b0..d1b8efb2f5 100644 --- a/api-server/src/server/boot/randomAPIs.js +++ b/api-server/src/server/boot/randomAPIs.js @@ -1,16 +1,10 @@ -import request from 'request'; - -import { gitHubUserAgent } from '../../../../config/misc'; import { getRedirectParams } from '../utils/redirection'; -const githubClient = process.env.GITHUB_ID; -const githubSecret = process.env.GITHUB_SECRET; - module.exports = function (app) { const router = app.loopback.Router(); const User = app.models.User; - router.get('/api/github', githubCalls); + router.get('/api/github', gone); router.get('/u/:email', unsubscribeDeprecated); router.get('/unsubscribe/:email', unsubscribeDeprecated); router.get('/ue/:unsubscribeId', unsubscribeById); @@ -18,6 +12,15 @@ module.exports = function (app) { app.use(router); + function gone(_, res) { + return res.status(410).json({ + message: { + type: 'info', + message: 'Please reload the app, this feature is no longer available.' + } + }); + } + function unsubscribeDeprecated(req, res) { req.flash( 'info', @@ -111,55 +114,4 @@ module.exports = function (app) { .catch(next); }); } - - function githubCalls(req, res, next) { - var githubHeaders = { - headers: { - 'User-Agent': gitHubUserAgent - }, - port: 80 - }; - request( - [ - 'https://api.github.com/repos/freecodecamp/', - 'freecodecamp/pulls?client_id=', - githubClient, - '&client_secret=', - githubSecret - ].join(''), - githubHeaders, - function (err, status1, pulls) { - if (err) { - return next(err); - } - pulls = pulls - ? Object.keys(JSON.parse(pulls)).length - : "Can't connect to github"; - - return request( - [ - 'https://api.github.com/repos/freecodecamp/', - 'freecodecamp/issues?client_id=', - githubClient, - '&client_secret=', - githubSecret - ].join(''), - githubHeaders, - function (err, status2, issues) { - if (err) { - return next(err); - } - issues = - pulls === parseInt(pulls, 10) && issues - ? Object.keys(JSON.parse(issues)).length - pulls - : "Can't connect to GitHub"; - return res.json({ - issues: issues, - pulls: pulls - }); - } - ); - } - ); - } }; diff --git a/config/misc.js b/config/misc.js index ec12ccb2b7..d2a04e7c7f 100644 --- a/config/misc.js +++ b/config/misc.js @@ -1,3 +1 @@ exports.defaultUserImage = 'https://freecodecamp.com/sample-image.png'; -exports.gitHubUserAgent = - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36';