Skip to content

Commit fffe90b

Browse files
author
nick
committed
fix:only support http/https to convert,disabled to reach file system.
1 parent 8126fb6 commit fffe90b

File tree

8 files changed

+51
-4
lines changed

8 files changed

+51
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
### v0.3.1
2+
- only support http/https to convert,disabled to reach file system.
13
### v0.3.0
24
- support waiting time for html convert to pdf
35
- support waiting time for html convert to image

CHECKLIST.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# check list
2+
- common/const.go Version
3+
- CHANGELOG.md
4+
- Makefile
5+
- merge branch
6+
- docker build and push to docker hub

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.DEFAULT: help
22

33
IMAGE_NAME ?= lampnick/doctron
4-
CENTOS_IMAGE_TAG ?= v0.3.0-centos
5-
ALPINE_IMAGE_TAG ?= v0.3.0-alpine
4+
CENTOS_IMAGE_TAG ?= v0.3.1-centos
5+
ALPINE_IMAGE_TAG ?= v0.3.1-alpine
66

77
help: Makefile
88
@echo "Doctron is a document convert tools for html pdf image etc.\r\n"

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Use this section to tell people about which versions of your project are
66
currently being supported with security updates.
77

88
| Version | Supported |
9-
| ------- | ------------------ |
9+
| 0.3.1 | ensure can't visit the file system |
1010

1111

1212
## Reporting a Vulnerability

app/http.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func NewDoctron() *iris.Application {
1919
}
2020
})
2121
app.PartyFunc("/convert", func(convert router.Party) {
22+
convert.Use(middleware.CheckParams)
2223
convert.Use(middleware.AuthMiddleware)
2324
convert.Use(middleware.CheckRateLimiting)
2425
convert.Get("/html2pdf", controller.Html2PdfHandler)

common/const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package common
22

33
//Version Version
4-
const Version = "0.3.0"
4+
const Version = "0.3.1"

common/error_code.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const (
77
InvalidParams = 10000001
88
InvalidUrl = 10000002
99
ApiRateLimitExceeded = 10000003
10+
InvalidUrlScheme = 10000004
1011
ConvertPdfFailed = 20000000
1112
ConvertPdfWriteBytesFailed = 20000001
1213
ConvertPdfUploadFailed = 20000002
@@ -28,6 +29,7 @@ var ErrMsg = map[int]string{
2829
InvalidParams: "invalid params",
2930
InvalidUrl: "invalid url",
3031
ApiRateLimitExceeded: "api rate limit exceeded",
32+
InvalidUrlScheme: "only support http/https",
3133
ConvertPdfFailed: "failed convert html to pdf",
3234
ConvertPdfWriteBytesFailed: "failed convert html to pdf. write bytes failed",
3335
ConvertPdfUploadFailed: "failed convert html to pdf. upload failed",

middleware/params.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package middleware
2+
3+
import (
4+
"net/url"
5+
6+
"github.com/kataras/iris/v12"
7+
"github.com/lampnick/doctron/common"
8+
)
9+
10+
func CheckParams(ctx iris.Context) {
11+
webUrl := ctx.URLParam("url")
12+
if webUrl == "" {
13+
outputDTO := common.NewDefaultOutputDTO(nil)
14+
outputDTO.Code = common.InvalidUrl
15+
_, _ = common.NewJsonOutput(ctx, outputDTO)
16+
return
17+
}
18+
19+
u, err := url.Parse(webUrl)
20+
if err != nil {
21+
outputDTO := common.NewDefaultOutputDTO(nil)
22+
outputDTO.Code = common.InvalidUrl
23+
outputDTO.Message = err.Error()
24+
_, _ = common.NewJsonOutput(ctx, outputDTO)
25+
return
26+
}
27+
28+
if u.Scheme != "http" && u.Scheme != "https" {
29+
outputDTO := common.NewDefaultOutputDTO(nil)
30+
outputDTO.Code = common.InvalidUrlScheme
31+
_, _ = common.NewJsonOutput(ctx, outputDTO)
32+
return
33+
}
34+
35+
ctx.Next()
36+
}

0 commit comments

Comments
 (0)