Skip to content

Commit b584112

Browse files
committed
Assume http protocol for inputs that have just the host name, and implement an additional defensive check that returns the input as is or throw an error
Signed-off-by: Arun <arun@arun.blog>
1 parent 8c9ade2 commit b584112

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/manifest/mod.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,25 @@ export const validateOutgoingDomains = (
3737
) => {
3838
return domains.map((domain) => {
3939
try {
40-
return new URL(domain).hostname;
40+
const url = domain.includes("://") ? domain : `http://${domain}`;
41+
return new URL(url).hostname;
4142
} catch (e) {
42-
return domain;
43+
if (isValidDomain(domain)) {
44+
return domain;
45+
} else {
46+
throw new Error(
47+
`Invalid outgoing domain: ${domain}, error ${e}`,
48+
);
49+
}
4350
}
4451
});
4552
};
4653

54+
const isValidDomain = (domain: string) => {
55+
const domainPattern = /^[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z]{2,}$/;
56+
return domainPattern.test(domain);
57+
};
58+
4759
export class SlackManifest {
4860
constructor(private definition: SlackManifestType) {
4961
this.registerFeatures();

0 commit comments

Comments
 (0)