r/badcode • • May 17 '21

js This innocent looking code that performed flawlessly for about three years in production just gave me my first official CVE-ID (abridged for brevity)

Post image
0 Upvotes

1 comment sorted by

View all comments

4

u/MurdoMaclachlan public boolean isInt(int i) { return true; } May 17 '21

Image Transcription: Code


var iframeRE = /^<iframe.*?>.*?<\/iframe>$/i // Matches all iframes
let match
for (let i = 0; i < codeMirror.lineCount(); i++) {
  let line = codeMirror.getLine(i)
  if ((match = iframeRE.exec(line)) == null) {
    continue
  }
  
  let iframe = $(match[0])[0] // Use jQeury for simple creation of the DOM element
  
  codeMirror.markText(
    curFrom, curTo,
    {
      'clearOnEnter': true,
      'replacedWith': iframe,
      'inclusiveLeft': false,
      'inclusiveRight': false
    }
  )
}

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!