tar-0.5.1.0: Reading, writing and manipulating ".tar" archive files.

Copyright | (c) 2008-2012 Duncan Coutts 2011 Max Bolingbroke
License | BSD3
Maintainer | duncan@community.haskell.org
Portability | portable
Safe Haskell | None
Language | Haskell98

Codec.Archive.Tar.Check

Contents

- Security
- Tarbombs
- Portability

Description

Perform various checks on tar file entries.

Synopsis

- checkSecurity :: Entries e -> Entries (Either e FileNameError)
- data FileNameError
  - = InvalidFileName FilePath
  - | AbsoluteFileName FilePath
- checkTarbomb :: FilePath -> Entries e -> Entries (Either e TarBombError)
- data TarBombError = TarBombError FilePath
- checkPortability :: Entries e -> Entries (Either e PortabilityError)
- data PortabilityError
  - = NonPortableFormat Format
  - | NonPortableFileType
  - | NonPortableEntryNameChar FilePath
  - | NonPortableFileName PortabilityPlatform FileNameError
- type PortabilityPlatform = String

# Security

checkSecurity :: Entries e -> Entries (Either e FileNameError) Source #

This function checks a sequence of tar entries for file name security problems. It checks that:

- file paths are not absolute
- file paths do not contain any path components that are "`..`"
- file names are valid

These checks are from the perspective of the current OS. That means we check for "`C:blah`" files on Windows and "/blah" files on Unix. For archive entry types `HardLink` and `SymbolicLink` the same checks are done for the link target. A failure in any entry terminates the sequence of entries with an error.

data FileNameError Source #

Errors arising from tar file names being in some way invalid or dangerous

Constructors

InvalidFileName FilePath |
AbsoluteFileName FilePath |

Instances

Show FileNameError Source # |
Instance details Defined in Codec.Archive.Tar.Check Methods showsPrec :: Int -> FileNameError -> ShowS Source # show :: FileNameError -> String Source # showList :: [FileNameError] -> ShowS Source #
Exception FileNameError Source # |
Instance details Defined in Codec.Archive.Tar.Check Methods toException :: FileNameError -> SomeException Source # fromException :: SomeException -> Maybe FileNameError Source # displayException :: FileNameError -> String Source #

# Tarbombs

checkTarbomb :: FilePath -> Entries e -> Entries (Either e TarBombError) Source #

This function checks a sequence of tar entries for being a "tar bomb". This means that the tar file does not follow the standard convention that all entries are within a single subdirectory, e.g. a file "foo.tar" would usually have all entries within the "foo/" subdirectory.

Given the expected subdirectory, this function checks all entries are within that subdirectroy.

Note: This check must be used in conjunction with `checkSecurity` (or `checkPortability`).

data TarBombError Source #

An error that occurs if a tar file is a "tar bomb" that would extract files outside of the intended directory.

Constructors

TarBombError FilePath |

Instances

Show TarBombError Source # |
Instance details Defined in Codec.Archive.Tar.Check Methods showsPrec :: Int -> TarBombError -> ShowS Source # show :: TarBombError -> String Source # showList :: [TarBombError] -> ShowS Source #
Exception TarBombError Source # |
Instance details Defined in Codec.Archive.Tar.Check Methods toException :: TarBombError -> SomeException Source # fromException :: SomeException -> Maybe TarBombError Source # displayException :: TarBombError -> String Source #

# Portability

checkPortability :: Entries e -> Entries (Either e PortabilityError) Source #

This function checks a sequence of tar entries for a number of portability issues. It will complain if:

- The old "Unix V7" or "gnu" formats are used. For maximum portability only the POSIX standard "ustar" format should be used.
- A non-portable entry type is used. Only ordinary files, hard links, symlinks and directories are portable. Device files, pipes and others are not portable between all common operating systems.
- Non-ASCII characters are used in file names. There is no agreed portable convention for Unicode or other extended character sets in file names in tar archives.
- File names that would not be portable to both Unix and Windows. This check includes characters that are valid in both systems and the '/' vs '\' directory separator conventions.

data PortabilityError Source #

Portability problems in a tar archive

Constructors

NonPortableFormat Format |
NonPortableFileType |
NonPortableEntryNameChar FilePath |
NonPortableFileName PortabilityPlatform FileNameError |

Instances

Show PortabilityError Source # |
Instance details Defined in Codec.Archive.Tar.Check Methods showsPrec :: Int -> PortabilityError -> ShowS Source # show :: PortabilityError -> String Source # showList :: [PortabilityError] -> ShowS Source #
Exception PortabilityError Source # |
Instance details Defined in Codec.Archive.Tar.Check Methods toException :: PortabilityError -> SomeException Source # fromException :: SomeException -> Maybe PortabilityError Source # displayException :: PortabilityError -> String Source #

type PortabilityPlatform = String Source #

The name of a platform that portability issues arise from