Coder Social home page Coder Social logo

psalm's People

Contributors

androlgenhald avatar arsn avatar bdsl avatar benmorel avatar boesing avatar bugreportuser avatar caugner avatar danog avatar dq5studios avatar elnoro avatar iluuu1994 avatar jack97 avatar joehoyle avatar lesuisse avatar lhchavez avatar lukasreschke avatar mpesari avatar mr-feek avatar muglug avatar orklah avatar pilif avatar signpostmarv avatar simpod avatar staabm avatar supersmile2009 avatar tysonandre avatar vincentlanglet avatar voku avatar vudaltsov avatar weirdan avatar

Watchers

 avatar  avatar

psalm's Issues

Idea: add a way to dump graph of taint edges from source and/or sink

E.g. dump a list of nodes that contain sources/sinks, and the edges that are connected to sources and/or sinks directly or indirectly, as well as what are escaped/removed/added by each function call.

This would help in checking that psalm is actually aware of the things that developers would consider sources/sinks that could be automatically inferred in a project.

Not sure if broadly useful

FalseableReturnStatement/NullableReturnStatement is extremely broad, would be emitted for attempting to return "T1|false" for a method returning "T2"

Not sure how best to handle this. I only skimmed the code, so my understanding might be limited. This doesn't contain a solution yet.

Possible ideas:

Only emit FalseableReturnStatement if at least one of the types overlaps with the return type, and false is another possible type that doesn't overlap.
Only emit FalseableReturnStatement if false is the only type which isn't allowed in the desired return type?

To do this, maybe TypeChecker could partition types into types which are subsumed, types which are completely invalid, and types which are less specific?

A bug was filed upstream.

Idea: Look into Transphpile for generating backports supporting php 5.6

The third party composer dependencies look like they may make that unviable (and break after composer upgrades), unless releases get limited to Phars or include composer.lock

This tool may potentially save some time in maintaining backports (and allow you to adopt php 7 syntax in master faster).

I worked on https://github.com/TysonAndre/Transphpile while looking at generating backports for a large php project. I had some fixes for the upstream that weren't yet merged.

That project can generate polyfills for param checks, return type checks, the ?? operator, (new Visitor())(), etc.

  • This would allow using php 7 features

Limitations:

  • Classes that don't exist in 5.6 require manual patching or polyfills
  • Some bugs in uncommon php syntax

convert_php70_to_php56.sh is an example of a script used to generate patches.


Example of how this would be used:

  1. Create a php56-uncompiled branch. Add any manual workarounds or stubs there, along with the script to convert to php 5.6.

    PHP-Parser 4.x depends on php 7.1. It might be possible to run Transphpile on nikic/php-parser (either at runtime or as part of the composer.phar install)

  2. Generate release branches by merging master into php56-uncompiled, creating a new branch, verifying that unit tests pass

Work on a demo plugin to make method calls affect taintedness of properties of a different class

<?php // --taint-analysis

// Has dynamic properties
class Other {
}

class X {
  /** @var Other */
  public $var;

  public function __construct(Other $x) {
    $this->var = $x;
  }

  public function set($name, $value) {
    $this->var->$name = $value;
  }
}

$x = new X();
$x->set('myname', $_GET['name']);
echo $x->var->myname;

calling X->set() should affect the taintedness of uses of OtherObject.

Hook\AfterMethodCallAnalysisInterface seems like the best way to do this.

Work on a plugin to add taint to array parameters of methods

It's possible for psalm to infer that individual array parameters are tainted based on calls.

Marking array['bad']-src/taint_mixed.php:195-216 as a source with the desired taint types (e.g. html for raw html) may be useful for API declarations that take dynamic input with configurable filters (along the lines of https://github.com/TysonAndre/psalm/blob/master/examples/plugins/APIFilterPlugin.php )

<?php
/**
 * @param array<string,string> $value
 */
function test_taint(array $value, array $other = []) {
    eval(htmlentities($value['bad']));
}
test_taint([
    'good' => 'some literal',
    'bad' => $_GET['evil'],
]);

With manual logging of the node ids:

../psalm/psalm --taint-analysis
Scanning files...
Analyzing files...

░Sources:
$_GET:src/taint_mixed.php:204
Edges:
From test_taint#1
-> $value['bad']-src/taint_mixed.php:129-134
From call to htmlentities-src/taint_mixed.php:129-141
-> htmlentities#1-src/taint_mixed.php:116
From $value['bad']-src/taint_mixed.php:129-134
-> call to htmlentities-src/taint_mixed.php:129-141
From htmlentities#1-src/taint_mixed.php:116
-> htmlentities-src/taint_mixed.php:116(escape html)
From htmlentities-src/taint_mixed.php:116
-> eval#1-src/taint_mixed.php:116
From $_GET:src/taint_mixed.php:204
-> $_GET['evil']-src/taint_mixed.php:204-208
From $_GET['evil']-src/taint_mixed.php:204-208
-> array['bad']-src/taint_mixed.php:195-216
From call to test_taint-src/taint_mixed.php:159-219
-> test_taint#1
From array['bad']-src/taint_mixed.php:195-216
-> call to test_taint-src/taint_mixed.php:159-219
Sinks:
eval#1-src/taint_mixed.php:116


ERROR: TaintedInput - src/taint_mixed.php:6:10 - Detected tainted text in path: $_GET -> $_GET['evil'] (src/taint_mixed.php:10:14) -> array['bad'] (src/taint_mixed.php:10:5) -> call to test_taint (src/taint_mixed.php:8:12) -> test_taint#1 (src/taint_mixed.php:5:27) -> $value['bad'] (src/taint_mixed.php:6:23) -> call to htmlentities (src/taint_mixed.php:6:23) -> htmlentities#1 (src/taint_mixed.php:6:23) -> htmlentities (src/taint_mixed.php:6:10) -> eval#1 (src/taint_mixed.php:6:10) (see https://psalm.dev/205)
    eval(htmlentities($value['bad']));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.