Skip to content

v0.91.0

Choose a tag to compare

@github-actions github-actions released this 05 Nov 22:01
· 416 commits to main since this release
f607ebd

Added

  • <issueHandlers> accepts Psalm's path-scoped <errorLevel type="..."><directory/><file/></errorLevel> blocks, with <referencedClass>, <referencedFunction>, <referencedMethod>, <referencedProperty>, <referencedConstant> and <referencedVariable> filters.
  • Release builds include an x86_64-apple-darwin binary again.
  • Taint sinks. TaintedHtml: print_r, var_export and highlight_string without the return flag, var_dump. TaintedSql: mysqli_execute_query, mysqli::execute_query, SQLite3::querySingle, mysqli_stmt::prepare, sqlsrv_query, sqlsrv_prepare and Doctrine DBAL Connection query methods (only the first argument of a method sink counts, so bound parameters aren't reported). TaintedSsrf: ftp_connect, ftp_ssl_connect, ssh2_connect, ldap_connect, socket_connect. TaintedLdap, for the DN: ldap_bind, ldap_add, ldap_modify, ldap_mod_add, ldap_mod_del, ldap_mod_replace, ldap_rename. TaintedFile: chgrp, finfo_file, exif_read_data, exif_thumbnail, imagecreatefrom*. TaintedUnserialize: igbinary_unserialize, yaml_parse, session_decode. TaintedHeader: CURLOPT_HTTPHEADER in curl_setopt or a literal curl_setopt_array. mb_send_mail headers and additional parameters are sinks, as for mail.
  • Taint sources: Laravel's $request->name and $request['name'], like $request->input('name'); $_SERVER['REMOTE_HOST'], $_SERVER['REDIRECT_HTTP_*'] and getenv('HTTP_*').
  • Docblocks: __benevolent<T>, closed-resource and properties-of<T> (and its public-, protected-, private- forms) are types instead of class names; @phpstan-method, @phpstan-property, @phpstan-property-read, @phpstan-property-write, @psalm-throws and @phpstan-throws are read, and a prefixed @method/@property tag overrides a plain one for the same name.

Changed

  • Breaking: --set-baseline without a file name writes mir-baseline.xml and deletes psalm-baseline.xml in the current directory. Auto-discovery and --update-baseline prefer mir-baseline.xml and fall back to psalm-baseline.xml.
  • Breaking: tainted file paths, include/require paths, eval() code and unserialize() payloads report TaintedFile (MIR0811), TaintedInclude (MIR0812), TaintedEval (MIR0813) and TaintedUnserialize (MIR0814) instead of TaintedInput, so Psalm-named suppressions match them. So do @taint-sink file|include|eval|unserialize parameters. Baseline entries recorded as TaintedInput still match. An <issueHandlers> entry for TaintedInput doesn't cover them: add the new names.
  • Breaking: mir_analyzer::cache::AnalysisCache::matches_content is removed, and mir_codebase::TaintAnnotations has a new public field, source.
  • ImpossibleIdenticalComparison and ImpossibleLooseComparison follow Psalm's level for TypeDoesNotContainType (4), so errorLevel 5 and above report them as info.
  • Workspace and internal crate versions were updated to 0.91.0.

Fixed

  • Output and the exit code use the severity from <issueHandlers>, scoped <errorLevel> blocks and errorLevel: a handler that lowers an error to a warning no longer fails the run, and one that raises a warning to an error does.
  • Baseline commands exit with code 2 in three cases: --update-baseline without a usable baseline, such as a mistyped --baseline or --ignore-baseline, which wrote an empty mir-baseline.xml that shadowed psalm-baseline.xml; --set-baseline src/a.php or --set-baseline src, which overwrote the PHP source; a failed baseline write, which reported success.
  • Baseline scope: a partial --update-baseline (mir src/Foo.php) keeps the entries of files it didn't analyze, and --report-stale-baseline doesn't report them as stale; on a full run, entries of ignored files do go stale.
  • Baseline keys: mir . writes src/a.php instead of ./src/a.php, matching Psalm baselines; Windows writes /, so a baseline matches on other platforms; keys are relative to the baseline's directory when it contains the file. Existing ./-prefixed entries, \-separated entries on Windows and keys relative to the working directory (--baseline ../b.xml, --baseline build/b.xml) still match, and a partial --update-baseline keeps them.
  • Taint guards clear their subject in more forms: a guard stored in a variable ($ok = ctype_digit($x); if ($ok)); an arm condition of match (true); (string) $x, strtolower($x) === 'jpg', trim($x) === 'a', $x == 'a' and non-strict in_array with literals; in_array($x, self::ALLOWED, true), a global const list and $x === self::A; isset($map[$x]) and array_key_exists($x, $map) when the map's keys are all literal; is_numeric and is_int-style checks on an array element; a passing filter_var($x, FILTER_VALIDATE_*), for the kinds its characters can't break, in the !== false, truthy and === false exit forms; a passing anchored preg_match($pattern, $x, $m), which also clears $m; a failed preg_match('/[<>"\']/', $x), for the kinds those characters are needed for, as in WordPress's _wp_specialchars (a /u pattern doesn't count: invalid UTF-8 makes it return false); inside a PHP_SAPI === 'cli' or in_array(PHP_SAPI, ['cli', 'phpdbg'], true) check, $_SERVER entries, which come from the process environment (this clears Symfony's httpoxy guard).
  • Taint is cleared by more operations: abs, round, floor and ceil; FILTER_SANITIZE_ADD_SLASHES for SQL and FILTER_SANITIZE_STRING for HTML; filter_var_array and filter_input_array definitions, per key; FILTER_CALLBACK with a named escaper; HTMLPurifier::purify for HTML; Symfony's getDigits, getAlnum and getAlpha bag getters; array_filter($a, 'is_numeric') and other named value checks, for the kept elements; a user function or method that sanitizes a by-ref argument (function s(string &$x) { $x = htmlspecialchars($x); }); unset($a['x']), for that element's share of the array; a clean write to a superglobal element ($_POST['n'] = (int) $_POST['n']); a value replaced on the failing path of a guard (if (!ctype_digit($x)) { $x = '0'; } echo $x;) or on every path of a branch, after the merge.
  • Taint false positives: Symfony's getClientIp, getClientIps and Laravel's ip, ips aren't sources, since they return addresses validated with FILTER_VALIDATE_IP; a project's own global request() or e() is analyzed by its body instead of being treated as Laravel's helper; a URL whose scheme and host come from a literal local, a constant or a sprintf format doesn't report TaintedSsrf or TaintedFile for what is appended; fprintf and vfprintf to STDERR aren't HTML output; unserialize with allowed_classes set to [] or a literal class list, or with the options in a local, isn't reported; @taint-source <kind> taints the return value with that kind only, so @psalm-taint-source shell no longer reports at HTML sinks (a bare tag and input still mean every kind).
  • Missed taint: filter_var, filter_input and their _array forms read named arguments by name, so filter_var(filter: FILTER_DEFAULT, value: $x) keeps the taint of $x; an empty default: falling into a case no longer clears its taint or narrows its type in that body; case true: no longer narrows a subject that may hold other types to true; a builtin sink named as a callback (call_user_func('system', $x), array_map('shell_exec', $_GET)), a method callback ([$o, 'out'], [$this, 'out'], [A::class, 'out'], 'A::out') and a function or method with a @taint-sink parameter report the data a callback builtin hands them; base64_decode, hex2bin, urldecode, json_decode and similar decoders restore every kind, so base64_decode(base64_encode($x)) and urldecode(basename($x)) stay tainted; md5($x, true) and other raw digests, the uniqid prefix and number_format separators keep the taint of the argument they copy into the result.
  • Classes and calls: a closure rebound with an object as $newScope ($f->bindTo($obj, $obj), Closure::bind($f, $obj, $obj)) is scoped to that object's class; an anonymous class is typed as its supertypes instead of object unless it declares public members they lack; Composer\Autoload\ClassLoader resolves from vendor/composer/ClassLoader.php, which Composer leaves out of the classmap; a class declared under a class_alias() target name (the if (false) { class Alias {} } IDE stub) inherits the aliased class; a thrown intersection with a Throwable part (A&B, or an anonymous class extending an exception) isn't InvalidThrow; a protected method is callable from an ancestor of the class that declares or overrides it; calls and property reads on an FFI instance aren't undefined; a call on an intersection A&I uses the method A declares, not an @method on I with a different signature; new $obj() is typed as $obj's class; UndefinedTrait names a namespaced trait by its fully qualified name.
  • Callables: callable is accepted where string|array|object is expected; [$string, 'method'] is accepted as a callable (a literal first element still has to name a class); an open array shape isn't rejected for lacking exactly two entries.
  • Docblocks: parent resolves to the parent class in a called method's return type and in declared-return checks (in a trait, to the parent of the class using it); self/parent in an inline @var resolve to the enclosing class; an inline @var resolves Enum::CASE in a generic argument against the file's imports; object{prop: T, ...} keeps its properties instead of becoming plain object, so $o->prop gives T and a shape argument missing a required property or with an incompatible property type is InvalidArgument; a plain /* */ comment before a statement no longer picks up a docblock from further up, such as a property's @var; @since/@removed tags in vendor code aren't read as PHP versions, so a library method tagged @since 8.4 stays defined when targeting PHP 8.0.
  • Templates: @return self<...> keeps its type arguments, so Symfony Config builder chains (->arrayPrototype()->...->end()) return the right level; a template-typed property read or written through $this stays the open template; new keeps a literal template argument when the bound admits only literals (new TreeBuilder($n, 'array') is a TreeBuilder<'array'>); a wider scalar bound to a literal-only bound (of 1|2) isn't InvalidTemplateParam; a static method's own @template T is inferred from the call instead of taking the type bound to a same-named class template through @extends; for @param T|U, an argument binds the template whose bound accepts it, so T of Enum and U of value-of<T> accept an enum case or its value; a parent's @param T no longer narrows a child parameter whose native type adds null (?T); a method returning a class template on a receiver with no type arguments (Iterator::current()) gives mixed.
  • Conditional types: an omitted argument binds its template and resolves a conditional @return from a null/true/false, integer or self::CONST default, so ContainerInterface::get($id) returns object; a union subject (($b is 0|1 ? A : B)) resolves at the call site; ($c is class-string ? A : B) resolves for a Foo::class argument and for a non-string argument; an override without @return inherits the parent's conditional @return when every branch, with method templates at their bounds, fits its native return type; a conditional @param-out resolves against the call's arguments instead of nesting on every loop pass.
  • static and $this returns: a method with @psalm-this-out and @return $this returns the receiver's new type; static or $this, also nested as in list<static>, called on an A&B receiver returns A&B.
  • Narrowing: !is_callable($x) removes Closure; $x === [] and $x == [] remove object types; ($x ?? false) !== false removes the fallback literal as well as null; if ($a['k']) narrows the shape key's value to truthy; the false branch of method_exists($mixed, ...) stays mixed; is_string($x ??= ...) and similar checks narrow $x; if ($isNew = null === $h) narrows $h; a variable holding $x instanceof C, is_*($x) or null === $x narrows $x when tested, until either variable changes; $x instanceof A || $x instanceof B keeps the B case when A extends the type of $x and B is an unrelated interface, and keeps an intersection that already satisfies one of the classes whole; instanceof C narrows A&(B|C) to C, and a union with a class that may also implement C to C rather than C|Other&C.
  • Flow: a loop that always runs at least once (a foreach over a non-empty array, while (true)) checks its body against the pre-loop state too; catch and finally see the value a variable held after each statement of the try body; on the path that short-circuits past an assignment (A && !$x = f(), A || $x = f()), $x keeps its previous type; a -> call or property read after ?-> in the same chain can be null; a mixed value assigned to a nullable property leaves it mixed; a trait method that writes no property no longer clears the property narrowing of $this, the same as a class method.
  • Expressions and arrays: a void call on the left of ?? evaluates to null; negating floor()/ceil()'s integral float keeps it integral, and an integral float fits a ?int parameter; |, & and ^ of two integer literals fold to a literal, so preg_match_all() with PREG_OFFSET_CAPTURE | PREG_SET_ORDER types $matches by its flags; $array + $other with a non-shape left operand includes the right operand's keys and values; ++$a[$k], $a[$k]++ and their -- forms update the int element; values assigned to a by-reference foreach variable become the element type of the iterated array or list; an array shape is checked against array<K, V> with the class hierarchy, so ['a' => Sub::class] fits an array<string, class-string<Parent>> property.
  • Builtins: version_compare() returns bool with an operator and int without; glob() returns list<string>|false; getenv() with an int, int|string or mixed name returns string|false; IntlGregorianCalendar::__construct() and intlgregcal_create_instance() take optional arguments, including a time zone and locale; pg_fetch_result(), pg_field_is_null() and pg_field_prtlen() accept the two-argument form and a null row; a defensive false === hrtime() check isn't an impossible comparison; array_merge() and array_replace() keep the key type of arrays with mixed values, and array_replace() keeps its arguments' key and value types; reset(), end(), next() and prev() leave the array argument's type unchanged; sort(), rsort(), usort() and shuffle() turn an array with unknown elements into a list<mixed>.
  • Long-running sessions: a warm LSP start keeps and serves cached results with unresolved names, evicting only results missing a name that newly registered or adopted files declare, and seeding the index or ingesting an already-indexed file doesn't mark replayed references stale; changing a declaration's kind with the same name (class Foo → interface Foo) no longer leaves it unresolvable.