backend-common: include port in url reader allow list check
This commit is contained in:
Vendored
+2
-1
@@ -105,9 +105,10 @@ export interface Config {
|
||||
*/
|
||||
allow?: Array<{
|
||||
/**
|
||||
* A hostname to allow outgoing requests to, being either a full hostname or
|
||||
* A host to allow outgoing requests to, being either a full host or
|
||||
* a subdomain wildcard pattern with a leading `*`. For example `example.com`
|
||||
* and `*.example.com` are valid values, `prod.*.example.com` is not.
|
||||
* The host may also contain a port, for example `example.com:8080`.
|
||||
*/
|
||||
host: string;
|
||||
}>;
|
||||
|
||||
@@ -35,7 +35,12 @@ describe('FetchUrlReader', () => {
|
||||
config: new ConfigReader({
|
||||
backend: {
|
||||
reading: {
|
||||
allow: [{ host: 'example.com' }, { host: '*.examples.org' }],
|
||||
allow: [
|
||||
{ host: 'example.com' },
|
||||
{ host: 'example.com:700' },
|
||||
{ host: '*.examples.org' },
|
||||
{ host: '*.examples.org:700' },
|
||||
],
|
||||
},
|
||||
},
|
||||
}),
|
||||
@@ -50,9 +55,19 @@ describe('FetchUrlReader', () => {
|
||||
|
||||
expect(predicate(new URL('https://example.com/test'))).toBe(true);
|
||||
expect(predicate(new URL('https://a.example.com/test'))).toBe(false);
|
||||
expect(predicate(new URL('https://example.com:600/test'))).toBe(false);
|
||||
expect(predicate(new URL('https://a.example.com:600/test'))).toBe(false);
|
||||
expect(predicate(new URL('https://example.com:700/test'))).toBe(true);
|
||||
expect(predicate(new URL('https://a.example.com:700/test'))).toBe(false);
|
||||
expect(predicate(new URL('https://other.com/test'))).toBe(false);
|
||||
expect(predicate(new URL('https://examples.org/test'))).toBe(false);
|
||||
expect(predicate(new URL('https://a.examples.org/test'))).toBe(true);
|
||||
expect(predicate(new URL('https://a.b.examples.org/test'))).toBe(true);
|
||||
expect(predicate(new URL('https://examples.org:600/test'))).toBe(false);
|
||||
expect(predicate(new URL('https://a.examples.org:600/test'))).toBe(false);
|
||||
expect(predicate(new URL('https://a.b.examples.org:600/test'))).toBe(false);
|
||||
expect(predicate(new URL('https://examples.org:700/test'))).toBe(false);
|
||||
expect(predicate(new URL('https://a.examples.org:700/test'))).toBe(true);
|
||||
expect(predicate(new URL('https://a.b.examples.org:700/test'))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -39,9 +39,9 @@ export class FetchUrlReader implements UrlReader {
|
||||
const host = allowConfig.getString('host');
|
||||
if (host.startsWith('*.')) {
|
||||
const suffix = host.slice(1);
|
||||
return (url: URL) => url.hostname.endsWith(suffix);
|
||||
return (url: URL) => url.host.endsWith(suffix);
|
||||
}
|
||||
return (url: URL) => url.hostname === host;
|
||||
return (url: URL) => url.host === host;
|
||||
}) ?? [];
|
||||
|
||||
const reader = new FetchUrlReader();
|
||||
|
||||
Reference in New Issue
Block a user