mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-21 22:44:06 +01:00
Improve kernel API authentication (#9702)
* 🎨 Add API `/api/network/echo` * 🎨 Improve localhost checking * 🎨 Add `model.CheckReadonly` for some APIs /api/storage/setLocalStorage /api/storage/setLocalStorageVal /api/notebook/openNotebook /api/notebook/removeNotebook /api/search/removeTemplate /api/attr/setBlockAttrs /api/sync/importSyncProviderS3 /api/sync/importSyncProviderWebDAV /api/riff/resetRiffCards /api/snippet/setSnippet /api/av/setAttributeViewBlockAttr /api/archive/zip /api/archive/unzip * 🎨 Remove `model.CheckReadonly` for some APIs /api/history/searchHistory /api/history/getHistoryItems /api/search/findReplace /api/block/getParentNextChildID /api/file/readDir /api/sync/listCloudSyncDir /api/asset/getDocImageAssets /api/template/renderSprig /api/ai/chatGPT /api/ai/chatGPTWithAction * 🎨 improve API `/api/network/echo`
This commit is contained in:
parent
70b3406e03
commit
cb016aac14
5 changed files with 110 additions and 51 deletions
|
|
@ -47,23 +47,8 @@ func ValidOptionalPort(port string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func SplitHost(host string) (hostname, port string) {
|
||||
hostname = host
|
||||
|
||||
colon := strings.LastIndexByte(hostname, ':')
|
||||
if colon != -1 && ValidOptionalPort(hostname[colon:]) {
|
||||
hostname, port = hostname[:colon], hostname[colon+1:]
|
||||
}
|
||||
|
||||
if strings.HasPrefix(hostname, "[") && strings.HasSuffix(hostname, "]") {
|
||||
hostname = hostname[1 : len(hostname)-1]
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func IsLocalHostname(hostname string) bool {
|
||||
if "localhost" == hostname {
|
||||
if "localhost" == hostname || strings.HasSuffix(hostname, ".localhost") {
|
||||
return true
|
||||
}
|
||||
if ip := net.ParseIP(hostname); nil != ip {
|
||||
|
|
@ -73,8 +58,11 @@ func IsLocalHostname(hostname string) bool {
|
|||
}
|
||||
|
||||
func IsLocalHost(host string) bool {
|
||||
hostname, _ := SplitHost(host)
|
||||
return IsLocalHostname(hostname)
|
||||
if hostname, _, err := net.SplitHostPort(strings.TrimSpace(host)); nil != err {
|
||||
return false
|
||||
} else {
|
||||
return IsLocalHostname(hostname)
|
||||
}
|
||||
}
|
||||
|
||||
func IsLocalOrigin(origin string) bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue