Giter VIP home page Giter VIP logo

Comments (9)

x00mario avatar x00mario commented on July 20, 2024

A small add-on - this might be safer - even in case an attacker managed to tamper with the existing constructors:

delete Object;
window instanceof ({}).constructor; // true

from forge.

dlongley avatar dlongley commented on July 20, 2024

Is there a specific reason why these kinds of checks are being used? Why not make use of instanceof?

This is a result of very old code that needs updating. A shared isArray call is in forge.util (but it still needs to be updated itself). Also, see:

http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/

We need to update forge.util.isArray() and use it where applicable.

from forge.

x00mario avatar x00mario commented on July 20, 2024

@kangax is - from what I can see - mainly concerned about cross-origin/-frame scenarios and the fragility of instanceof therein. Are they relevant in this situation?

from forge.

dlongley avatar dlongley commented on July 20, 2024

@x00mario, well, forge was actually originally created specifically to be used in cross-origin/-frame scenarios -- however, the point of linking to that article was that we should probably adopt the solution given at the end (it has worked well elsewhere):

function isArray(o) {
  return Object.prototype.toString.call(o) === '[object Array]';
}

A combination of Array.isArray (if it exists) and then falling back to the above check would probably be best/most compatible.

from forge.

dlongley avatar dlongley commented on July 20, 2024

There is also the hideous mess found here:

http://stackoverflow.com/questions/1058427/how-to-detect-if-a-variable-is-an-array

from forge.

kangax avatar kangax commented on July 20, 2024

@dlongley You can also: util.isArray = Array.isArray || function(){ ... } since Array.isArray does the same check (against [[Class]]) and is pretty widely supported by now — http://kangax.github.io/es5-compat-table/#Array.isArray

from forge.

dlongley avatar dlongley commented on July 20, 2024

@kangax -- yeah, that's what I went with, thanks.

from forge.

kangax avatar kangax commented on July 20, 2024

@dlongley Ah cool. Didn't notice first condition.

from forge.

dlongley avatar dlongley commented on July 20, 2024

Yeah, I consolidated that to make it more clear.

from forge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.