id: npmignore-disclosure

info:
  name: NPM .npmignore File Disclosure
  author: 0x_Akoko
  severity: info
  description: |
    Detected NPM .npmignore configuration file, potentially exposing excluded files and project structure information.
  reference:
    - https://docs.npmjs.com/cli/v9/using-npm/developers#keeping-files-out-of-your-package
    - https://docs.npmjs.com/cli/v9/configuring-npm/npmignore
  metadata:
    verified: true
    max-request: 5
    shodan-query: http.html:".npmignore"
    fofa-query: body=".npmignore"
  tags: exposure,npm,config,node

http:
  - method: GET
    path:
      - "{{BaseURL}}/.npmignore"
      - "{{BaseURL}}/node_modules/.npmignore"
      - "{{BaseURL}}/src/.npmignore"
      - "{{BaseURL}}/api/.npmignore"
      - "{{BaseURL}}/backend/.npmignore"

    stop-at-first-match: true

    matchers-condition: and
    matchers:
      - type: status
        status:
          - 200

      - type: word
        part: body
        words:
          - "node_modules"
        condition: and

      - type: word
        part: body
        words:
          - ".*"
          - "*~"
          - "*.swp"
          - "*.log"
          - "*.md"
          - ".git"
        condition: or

      - type: word
        part: body
        negative: true
        words:
          - "<html"
          - "<body"
          - "<!DOCTYPE"
          - "<script"
          - "<?php"

      - type: dsl
        dsl:
          - 'len(body) > 20 && len(body) < 5000'
          - 'content_type != "text/html"'
          - 'contains(body, "\n")'
          - '!contains(tolower(body), "error")'
          - '!contains(tolower(body), "not found")'
        condition: and
# digest: 4a0a00473045022100c180d85bfa86b9085985c758bd5b97b696d806730b47d4a6c09cafbdce95843b02200a439a7357d1281bd4b603a850adaf944bdb8815d46c58cdcc033f157a220fd4:922c64590222798bb761d5b6d8e72950