You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The .test function is called, although this function retains state in the regex object. E.g. on first invocation, it will go through the regex until it is matched, and return the result. On second invocation, it will go through the remainder of the regex and reset, returning a wrong result. Then on the third invocation it produces the right result again. This behaviour is also described on the MDN page of the function:
As with exec() (or in combination with it), test() called multiple times on the same global regular expression instance will advance past the previous match.
Steps to Reproduce
Initialize the plugin with a Regex or list of regexes:
Now every other request from e.g. https://www.floodtags.com/ will not get the correct Access-Control-Allow-Origin header
Expected Behavior
The 'isRequestOriginAllowed' should return the same result on every invocation.
This can be achieved by e.g. using the String.match function instead of Regex.test. I can submit a pull-request for this if needed, please let me know!
The text was updated successfully, but these errors were encountered:
#152)
The 'isRequestOriginAllowed' function returned random results for
global regexes, since the .test function was used, and the output
of this function depends on previous invocations of the function. By
resetting the 'lastIndex', every invocation of the function should now
return the same result.
This also updates the corresponding test to use a global regex, and do
the same validation twice, in order to check consistency
fixes#151
Co-authored-by: Tom Brouwer <brouwer@floodtags.com>
Prerequisites
Fastify version
3.20.2
Plugin version
6.0.2
Node.js version
16.6.2
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
PopOS 20.04
Description
Every other request, the isRequestOriginAllowed function, will return an invalid result, in case a Regex is used.
The behaviour can be tracked back to this line in the code
The .test function is called, although this function retains state in the regex object. E.g. on first invocation, it will go through the regex until it is matched, and return the result. On second invocation, it will go through the remainder of the regex and reset, returning a wrong result. Then on the third invocation it produces the right result again. This behaviour is also described on the MDN page of the function:
Steps to Reproduce
Initialize the plugin with a Regex or list of regexes:
Now every other request from e.g.
https://www.floodtags.com/
will not get the correctAccess-Control-Allow-Origin
headerExpected Behavior
The 'isRequestOriginAllowed' should return the same result on every invocation.
This can be achieved by e.g. using the String.match function instead of Regex.test. I can submit a pull-request for this if needed, please let me know!
The text was updated successfully, but these errors were encountered: