Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- XML validator no longer hangs on recursive DTD entity expansion (closes #503).
- TOML files with duplicate keys are now rejected as invalid (closes #504).
- Broken symlinks are reported as validation failures instead of aborting the run (closes #505)
- Repeating the same `--reporter` type with different output paths now writes each requested output.
Expand Down
13 changes: 13 additions & 0 deletions pkg/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1180,3 +1180,16 @@ func Test_JustfileValidateValid(t *testing.T) {
require.True(t, valid)
require.NoError(t, err)
}

func Test_XMLRecursiveEntityDoesNotHang(t *testing.T) {
t.Parallel()
recursive := []byte(`<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY a "&b;">
<!ENTITY b "&a;">
]>
<foo>&a;</foo>`)
valid, err := XMLValidator{}.ValidateSyntax(recursive)
require.False(t, valid)
require.Error(t, err)
}
4 changes: 3 additions & 1 deletion pkg/validator/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"regexp"
"strconv"
"strings"
"time"

"github.com/lestrrat-go/helium"
"github.com/lestrrat-go/helium/xsd"
Expand All @@ -30,7 +31,8 @@ func (XMLValidator) ValidateXSD(b []byte, schemaPath string) (bool, error) {
}

func (XMLValidator) ValidateSyntax(b []byte) (bool, error) {
ctx := context.Background()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add the same timeout to ValidateXSD — it has the same context.Background() pattern and the same risk:

func ValidateXSD(b []byte, schemaPath string) (bool, error) {
    ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
    defer cancel()
    ....

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MD-Mushfiqur123 Need to address this

defer cancel()
_, err := helium.NewParser().ValidateDTD(true).Parse(ctx, b)
if err != nil {
errMsg := err.Error()
Expand Down