@ -284,18 +284,12 @@ func (x *Noxer) verifyEventLink(ctx context.Context, eventID, relayURL, link str
// link not found in the event text/json.
// check URLs in OGP metadata for each suitable link found in the event.
for _ , urlStr := range eventURLs {
u , err := url . Parse ( urlStr )
if err != nil {
continue // invalid url
}
if ext := path . Ext ( u . Path ) ; ext != "" {
if ! strings . HasSuffix ( ext , "html" ) && ! strings . HasSuffix ( ext , "htm" ) {
continue // assume not an html page
}
if ! validOGPCandidate ( urlStr ) {
continue
}
meta , err := x . slurpLinkMeta ( ctx , urlStr )
if err != nil {
log . Printf ( "verifyEventLink slurpLinkMeta(%s): %v" , u , err )
log . Printf ( "verifyEventLink slurpLinkMeta(%s): %v" , urlStr , err )
continue
}
for _ , imgURL := range meta . ImageURLs {
@ -591,3 +585,23 @@ func validURL(urlStr string) bool {
}
return u . Scheme == "" || u . Scheme == "http" || u . Scheme == "https"
}
// must be sorted in lexical order
var knownOGPHosts = [ ] string {
"opengraph.githubassets.com" ,
}
// reports whether urlStr looks like a URL to an html page.
func validOGPCandidate ( urlStr string ) bool {
u , err := url . Parse ( urlStr )
if err != nil {
return false
}
ext := path . Ext ( u . Path )
if ext == "" || strings . HasSuffix ( ext , "html" ) || strings . HasSuffix ( ext , "htm" ) {
return true
}
host := u . Hostname ( )
i := sort . SearchStrings ( knownOGPHosts , host )
return i < len ( knownOGPHosts ) && knownOGPHosts [ i ] == host
}