|
| 1 | +import { givenUuid, currentTestEnvironment } from './__utils__' |
| 2 | +import { Instance } from '../src/utils' |
| 3 | + |
| 4 | +describe('blocks common hacker paths', () => { |
| 5 | + const env = currentTestEnvironment() |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + givenUuid({ |
| 9 | + __typename: 'Article', |
| 10 | + alias: '/legitimate-path', |
| 11 | + content: 'legitimate content', |
| 12 | + instance: Instance.En, |
| 13 | + }) |
| 14 | + }) |
| 15 | + |
| 16 | + test.each([ |
| 17 | + '/.env', |
| 18 | + '/.git', |
| 19 | + '/.aws/config', |
| 20 | + '/.ssh/id_rsa', |
| 21 | + '/.docker/config', |
| 22 | + '/config.json', |
| 23 | + '/config.php', |
| 24 | + '/configuration.php', |
| 25 | + ])('blocks file-based attack path: %s', async (path) => { |
| 26 | + const response = await env.fetch({ subdomain: 'en', pathname: path }) |
| 27 | + expect(response.status).toBe(404) |
| 28 | + }) |
| 29 | + |
| 30 | + test.each([ |
| 31 | + '/wp-admin', |
| 32 | + '/wp-login.php', |
| 33 | + '/wp-content/plugins', |
| 34 | + '/wp-includes/file.php', |
| 35 | + '/xmlrpc.php', |
| 36 | + '/wp-config.php', |
| 37 | + ])('blocks WordPress-related path: %s', async (path) => { |
| 38 | + const response = await env.fetch({ subdomain: 'en', pathname: path }) |
| 39 | + expect(response.status).toBe(404) |
| 40 | + }) |
| 41 | + |
| 42 | + test.each([ |
| 43 | + '/phpmyadmin', |
| 44 | + '/pma', |
| 45 | + '/admin', |
| 46 | + '/administrator', |
| 47 | + '/cpanel', |
| 48 | + '/plesk', |
| 49 | + '/webmail', |
| 50 | + '/joomla/admin', |
| 51 | + '/drupal/admin', |
| 52 | + ])('blocks CMS and admin panel path: %s', async (path) => { |
| 53 | + const response = await env.fetch({ subdomain: 'en', pathname: path }) |
| 54 | + expect(response.status).toBe(404) |
| 55 | + }) |
| 56 | + |
| 57 | + test.each([ |
| 58 | + '/test.php', |
| 59 | + '/index.asp', |
| 60 | + '/default.aspx', |
| 61 | + '/login.jsp', |
| 62 | + '/script.cgi', |
| 63 | + '/file.pl', |
| 64 | + ])('blocks disallowed file extension: %s', async (path) => { |
| 65 | + const response = await env.fetch({ subdomain: 'en', pathname: path }) |
| 66 | + expect(response.status).toBe(404) |
| 67 | + }) |
| 68 | + |
| 69 | + test('legitimate paths still work and redirect properly', async () => { |
| 70 | + const response = await env.fetch({ |
| 71 | + subdomain: 'en', |
| 72 | + pathname: '/legitimate-path', |
| 73 | + }) |
| 74 | + // This should not be blocked and should work as normal |
| 75 | + expect(response.status).not.toBe(404) |
| 76 | + }) |
| 77 | +}) |
0 commit comments