Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 57640cc

Browse files
committed
connector/saml: Validate XML roundtrip data before processing request
Signed-off-by: Stephen Augustus <[email protected]>
1 parent a136ab6 commit 57640cc

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

connector/saml/saml.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import (
77
"encoding/base64"
88
"encoding/pem"
99
"encoding/xml"
10-
"errors"
1110
"fmt"
1211
"io/ioutil"
1312
"strings"
1413
"sync"
1514
"time"
1615

1716
"github.com/beevik/etree"
17+
xrv "github.com/mattermost/xml-roundtrip-validator"
18+
"github.com/pkg/errors"
1819
dsig "github.com/russellhaering/goxmldsig"
1920
"github.com/russellhaering/goxmldsig/etreeutils"
2021

@@ -287,6 +288,7 @@ func (p *provider) POSTData(s connector.Scopes, id string) (action, value string
287288
//
288289
// The steps taken are:
289290
//
291+
// * Validate XML document does not contain malicious inputs.
290292
// * Verify signature on XML document (or verify sig on assertion elements).
291293
// * Verify various parts of the Assertion element. Conditions, audience, etc.
292294
// * Map the Assertion's attribute elements to user info.
@@ -297,6 +299,11 @@ func (p *provider) HandlePOST(s connector.Scopes, samlResponse, inResponseTo str
297299
return ident, fmt.Errorf("decode response: %v", err)
298300
}
299301

302+
byteReader := bytes.NewReader(rawResp)
303+
if xrvErr := xrv.Validate(byteReader); xrvErr != nil {
304+
return ident, errors.Wrap(xrvErr, "validating XML response")
305+
}
306+
300307
// Root element is allowed to not be signed if the Assertion element is.
301308
rootElementSigned := true
302309
if p.validator != nil {

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ require (
2323
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
2424
github.com/kylelemons/godebug v1.1.0
2525
github.com/lib/pq v1.3.0
26+
github.com/mattermost/xml-roundtrip-validator v0.0.0-20201204154048-1a8688af4cf1
2627
github.com/mattn/go-sqlite3 v1.11.0
28+
github.com/pkg/errors v0.9.1
2729
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
2830
github.com/prometheus/client_golang v1.4.0
2931
github.com/russellhaering/goxmldsig v1.1.0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+
186186
github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
187187
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
188188
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
189+
github.com/mattermost/xml-roundtrip-validator v0.0.0-20201204154048-1a8688af4cf1 h1:D2uMrH5NnWgU7JdjiWjOg/n31gbPH6I0D3IbCrqVVYE=
190+
github.com/mattermost/xml-roundtrip-validator v0.0.0-20201204154048-1a8688af4cf1/go.mod h1:qccnGMcpgwcNaBnxqpJpWWUiPNr5H3O8eDgGV9gT5To=
189191
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
190192
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
191193
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
@@ -226,6 +228,8 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
226228
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
227229
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
228230
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
231+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
232+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
229233
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
230234
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
231235
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAmPf4YLrFg6oQUotqHQeUNWwkvo7jZp1GLU=

0 commit comments

Comments
 (0)