Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
f8c973c9
Unverified
Commit
f8c973c9
authored
Feb 19, 2025
by
MHZ
Committed by
GitHub
Feb 19, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: prevent previewing internal network web pages. (#4421)
parent
2aaaef79
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletion
+26
-1
html_meta.go
plugin/httpgetter/html_meta.go
+26
-1
No files found.
plugin/httpgetter/html_meta.go
View file @
f8c973c9
...
@@ -3,6 +3,7 @@ package httpgetter
...
@@ -3,6 +3,7 @@ package httpgetter
import
(
import
(
"errors"
"errors"
"io"
"io"
"net"
"net/http"
"net/http"
"net/url"
"net/url"
...
@@ -17,7 +18,7 @@ type HTMLMeta struct {
...
@@ -17,7 +18,7 @@ type HTMLMeta struct {
}
}
func
GetHTMLMeta
(
urlStr
string
)
(
*
HTMLMeta
,
error
)
{
func
GetHTMLMeta
(
urlStr
string
)
(
*
HTMLMeta
,
error
)
{
if
_
,
err
:=
url
.
Parse
(
urlStr
);
err
!=
nil
{
if
err
:=
validateURL
(
urlStr
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -35,6 +36,8 @@ func GetHTMLMeta(urlStr string) (*HTMLMeta, error) {
...
@@ -35,6 +36,8 @@ func GetHTMLMeta(urlStr string) (*HTMLMeta, error) {
return
nil
,
errors
.
New
(
"not a HTML page"
)
return
nil
,
errors
.
New
(
"not a HTML page"
)
}
}
// TODO: limit the size of the response body
htmlMeta
:=
extractHTMLMeta
(
response
.
Body
)
htmlMeta
:=
extractHTMLMeta
(
response
.
Body
)
return
htmlMeta
,
nil
return
htmlMeta
,
nil
}
}
...
@@ -96,3 +99,25 @@ func extractMetaProperty(token html.Token, prop string) (content string, ok bool
...
@@ -96,3 +99,25 @@ func extractMetaProperty(token html.Token, prop string) (content string, ok bool
}
}
return
content
,
ok
return
content
,
ok
}
}
func
validateURL
(
urlStr
string
)
error
{
u
,
err
:=
url
.
Parse
(
urlStr
)
if
err
!=
nil
{
return
errors
.
New
(
"invalid URL format"
)
}
if
u
.
Scheme
!=
"http"
&&
u
.
Scheme
!=
"https"
{
return
errors
.
New
(
"only http/https protocols are allowed"
)
}
if
host
:=
u
.
Hostname
();
host
!=
""
{
ip
:=
net
.
ParseIP
(
host
)
if
ip
!=
nil
{
if
ip
.
IsLoopback
()
||
ip
.
IsPrivate
()
||
ip
.
IsLinkLocalUnicast
()
{
return
errors
.
New
(
"internal IP addresses are not allowed"
)
}
}
}
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment