Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
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
Alex
next.js
Commits
266c7ed7
Unverified
Commit
266c7ed7
authored
Nov 07, 2020
by
Joe Haddad
Committed by
GitHub
Nov 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add additional tests (#18597)
This PR adds additional security tests.
parent
2effca8e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
0 deletions
+130
-0
security.js
test/integration/basic/test/security.js
+17
-0
next.config.js
test/integration/production/next.config.js
+5
-0
security.js
test/integration/production/test/security.js
+108
-0
No files found.
test/integration/basic/test/security.js
View file @
266c7ed7
/* eslint-env jest */
/* eslint-env jest */
import
{
fetchViaHTTP
}
from
'next-test-utils'
import
{
fetchViaHTTP
}
from
'next-test-utils'
import
url
from
'url'
module
.
exports
=
(
context
)
=>
{
module
.
exports
=
(
context
)
=>
{
describe
(
'With Security Related Issues'
,
()
=>
{
describe
(
'With Security Related Issues'
,
()
=>
{
...
@@ -19,5 +20,21 @@ module.exports = (context) => {
...
@@ -19,5 +20,21 @@ module.exports = (context) => {
}
}
}
}
})
})
it
(
'should handle encoded / value for trailing slash correctly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
context
.
appPort
,
'/%2fexample.com/'
,
undefined
,
{
redirect
:
'manual'
}
)
const
{
pathname
,
hostname
}
=
url
.
parse
(
res
.
headers
.
get
(
'location'
)
||
''
)
expect
(
res
.
status
).
toBe
(
308
)
expect
(
pathname
).
toBe
(
'/%2fexample.com'
)
expect
(
hostname
).
not
.
toBe
(
'example.com'
)
})
})
})
}
}
test/integration/production/next.config.js
View file @
266c7ed7
...
@@ -29,6 +29,11 @@ module.exports = {
...
@@ -29,6 +29,11 @@ module.exports = {
destination
:
'/about'
,
destination
:
'/about'
,
permanent
:
false
,
permanent
:
false
,
},
},
{
source
:
'/redirect-query-test/:path'
,
destination
:
'/about?foo=:path'
,
permanent
:
false
,
},
]
]
},
},
}
}
test/integration/production/test/security.js
View file @
266c7ed7
...
@@ -234,5 +234,113 @@ module.exports = (context) => {
...
@@ -234,5 +234,113 @@ module.exports = (context) => {
'
url
=
https
%
3
A
%
2
F
%
2
Fgoogle
.
com
%
2
Fimage
%
3
Fcrop
%
3
Dfocalpoint
%
26
w
%
3
D24
&
w
=
1200
&
q
=
100
'
'
url
=
https
%
3
A
%
2
F
%
2
Fgoogle
.
com
%
2
Fimage
%
3
Fcrop
%
3
Dfocalpoint
%
26
w
%
3
D24
&
w
=
1200
&
q
=
100
'
)
)
})
})
it('
should
handle
encoded
value
in
the
pathname
correctly
/
', async () => {
const res = await fetchViaHTTP(
context.appPort,
'
/
redirect
/
me
/
to
-
about
/%
2
fgoogle
.
com
',
undefined,
{
redirect: '
manual
',
}
)
const { pathname, hostname } = url.parse(
res.headers.get('
location
') || ''
)
expect(res.status).toBe(307)
expect(pathname).toBe('
/%
2
fgoogle
.
com
/
about
')
expect(hostname).not.toBe('
google
.
com
')
})
it('
should
handle
encoded
value
in
the
pathname
to
query
correctly
(
/
)
', async
()
=>
{
const
res
=
await
fetchViaHTTP
(
context
.
appPort
,
'/redirect-query-test/%2Fgoogle.com'
,
undefined
,
{
redirect
:
'manual'
,
}
)
const
{
pathname
,
hostname
,
query
}
=
url
.
parse
(
res
.
headers
.
get
(
'location'
)
||
''
)
expect
(
res
.
status
).
toBe
(
307
)
expect
(
pathname
).
toBe
(
'/about'
)
expect
(
query
).
toBe
(
'foo=%2Fgoogle.com'
)
expect
(
hostname
).
not
.
toBe
(
'google.com'
)
expect
(
hostname
).
not
.
toMatch
(
/google/
)
})
it
(
'should handle encoded / value for trailing slash correctly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
context
.
appPort
,
'/%2fexample.com/'
,
undefined
,
{
redirect
:
'manual'
}
)
const
{
pathname
,
hostname
}
=
url
.
parse
(
res
.
headers
.
get
(
'location'
)
||
''
)
expect
(
res
.
status
).
toBe
(
308
)
expect
(
pathname
).
toBe
(
'/%2fexample.com'
)
expect
(
hostname
).
not
.
toBe
(
'example.com'
)
})
it
(
'should handle encoded value in the pathname correctly /'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
context
.
appPort
,
'/redirect/me/to-about/%2fgoogle.com'
,
undefined
,
{
redirect
:
'manual'
,
}
)
const
{
pathname
,
hostname
}
=
url
.
parse
(
res
.
headers
.
get
(
'location'
)
||
''
)
expect
(
res
.
status
).
toBe
(
307
)
expect
(
pathname
).
toBe
(
'/%2fgoogle.com/about'
)
expect
(
hostname
).
not
.
toBe
(
'google.com'
)
})
it
(
'should handle encoded value in the pathname to query correctly (/)'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
context
.
appPort
,
'/redirect-query-test/%2Fgoogle.com'
,
undefined
,
{
redirect
:
'manual'
,
}
)
const
{
pathname
,
hostname
,
query
}
=
url
.
parse
(
res
.
headers
.
get
(
'location'
)
||
''
)
expect
(
res
.
status
).
toBe
(
307
)
expect
(
pathname
).
toBe
(
'/about'
)
expect
(
query
).
toBe
(
'foo=%2Fgoogle.com'
)
expect
(
hostname
).
not
.
toBe
(
'google.com'
)
expect
(
hostname
).
not
.
toMatch
(
/google/
)
})
it
(
'should handle encoded / value for trailing slash correctly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
context
.
appPort
,
'/%2fexample.com/'
,
undefined
,
{
redirect
:
'manual'
}
)
const
{
pathname
,
hostname
}
=
url
.
parse
(
res
.
headers
.
get
(
'location'
)
||
''
)
expect
(
res
.
status
).
toBe
(
308
)
expect
(
pathname
).
toBe
(
'/%2fexample.com'
)
expect
(
hostname
).
not
.
toBe
(
'example.com'
)
})
})
})
}
}
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