MobSF / mobsfscan

mobsfscan is a static analysis tool that can find insecure code patterns in your Android and iOS source code. Supports Java, Kotlin, Swift, and Objective C Code. mobsfscan uses MobSF static analysis rules and is powered by semgrep and libsast pattern matcher.
GNU Lesser General Public License v3.0
607 stars 97 forks source link

Random errors for XML files: Syntax error at line file.xml:1:\n `?` was unexpected" #62

Closed antnks closed 10 months ago

antnks commented 1 year ago

Error in mobsfscan 0.2.2 output:

{"code":3,"level":"warn","message":"Syntax error at line file.xml:1:\n `?` was unexpected" ...snip...

The file looks like this:

<?xml version="1.0" encoding="utf-8"?>
...snip...

Which looks like a valid XML

Also another error:

{"code":3,"level":"warn","message":"Syntax error at line styles.xml:1:\n `\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cresources\u003e...snip...

That files is also a valid XML

ajinabraham commented 1 year ago

Thanks for reporting. Can you share a test file so that I can reproduce this issue at my end?

tosiara commented 1 year ago

You can use any xml file, like this (rename to xml): AndroidManifest.xml.txt

But keep in mind that the issue is random, sometimes it passes and outputs No issues found., and sometimes it generates syntax error. I think it fails to detect the file type and maybe treats it as kotlin?

tosiara commented 1 year ago

Yeah, you can reproduce if you give the file .java extension:

"errors": [
    {
      "code": 3,
      "level": "warn",
      "message": "Syntax error at line AndroidManifest.xml.java:1:\n `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<test>aaaaaaaaa</test>` was unexpected",
      "path": "AndroidManifest.xml.java",
      "spans": [
        {
          "end": {
            "col": 62,
            "line": 1
          },
          "file": "AndroidManifest.xml.java",
          "start": {
            "col": 1,
            "line": 1
          }
        }
      ],
      "type": "Syntax error"
    }
  ],
antnks commented 1 year ago

Hi, yes, it is random.

I have updated my docker to the latest mobsfscan and bumped all the dependencies, so far haven't see the issue. But need to wait a little until it reproduces.

Attaching the smallest file that triggered the issue last time:

include_feature.zip

antnks commented 1 year ago

If you need to add some debugging code or anything, please ping me in this thread I will be happy to help

ajinabraham commented 1 year ago

@tosiara This expected. It's an invalid java file.

@antnks I cannot reproduce this issue. We need a reproducible test case to debug this further.