urbanadventurer/WhatWeb · error

Error: You do not have permission to view #

Error message

Error: You do not have permission to view #{@target}

What it means

Raised in Target#initialize (lib/target.rb:188) when the target path exists but the process lacks read permission (File.readable? is false). WhatWeb cannot open the file to scan it, so target construction fails with a permission message naming the target.

Solutions

  1. chmod/chown the file so the running user can read it, or run whatweb as a user with access (sudo)
  2. Copy the file to a readable location before scanning
  3. Verify with ls -l / test -r "$TARGET" before running
  4. If in a container, mount the file read-only with correct uid/gid mapping

Example fix

# before
whatweb /root/captures/site.html
# after
sudo whatweb /root/captures/site.html
# or
chmod +r /root/captures/site.html
Defensive patterns

Strategy: validation

Validate before calling

target = '/path/to/file'
raise 'unreadable target' unless File.readable?(target)
# shell: test -r "$TARGET" || sudo whatweb "$TARGET"

Type guard

def readable_file?(t)
  File.file?(t) && File.readable?(t)
end

Try / catch

begin
  target = Target.new(path)
rescue RuntimeError => e
  raise unless e.message.start_with?('Error: You do not have permission')
  STDERR.puts "permission denied on #{path}; try sudo or chmod"
end

Prevention

When it happens

Trigger: Target.new('/path/to/file') where File.exist? is true but File.readable? is false — e.g. root-owned file with 0600, files under another user's home, or restrictive ACLs when running whatweb as an unprivileged user.

Common situations: Running whatweb without sudo against root-owned capture/target files; files created by another user with default umask 0077; mounted volumes or containers dropping read permissions; scanning a saved page owned by a service account.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


AI-assisted analysis of urbanadventurer/WhatWeb@d279d93042 (2026-09-15). Data as JSON: /api/errors/2778403a90eef7b8. Report an issue: GitHub.

Appendix: source

Thrown at lib/target.rb:188

  def initialize(target = nil, redirect_counter = 0)
    @target = target
    @redirect_counter = redirect_counter
    @headers = {}
    @http_options = { method: 'GET' }
    #		@status=0

    @is_url = if @target =~ /^http[s]?:\/\//
                true
              else
                false
              end

    if File.exist?(@target)
      @is_file = true
      raise "Error: #{@target} is a directory" if File.directory?(@target)
      if File.readable?(@target) == false
        raise "Error: You do not have permission to view #{@target}"
      end
    else
      @is_file = false
    end

    if is_url?
      @uri = URI.parse(Addressable::URI.encode(@target))

      # is this taking control away from the user?
      # [400] http://www.alexa.com  [200] http://www.alexa.com/
      @uri.path = '/' if @uri.path.empty?
    else
      # @uri=URI.parse("file://"+@target)
      @uri = URI.parse('')
    end
  end

  def open

View on GitHub (pinned to d279d93042)