Skip to content

[Taint-Analysis] Set Lift - #2799

Draft
EagleoutIce wants to merge 19 commits into
mainfrom
2689-set-lift
Draft

EagleoutIce wants to merge 19 commits into
mainfrom
2689-set-lift

Conversation

@EagleoutIce

Copy link
Copy Markdown
Member

No description provided.

Comment thread src/taint-analysis/finite-domain.ts Outdated
return this.create(this._value);
}

get elements(): ReadonlySet<Elements[number]> {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

klassisch gesehen ist das die domain

Comment thread src/taint-analysis/set-lift-domain.ts Outdated
value: Elements[number] | SetLiftValue<Elements[number]> = new Set()
) {
const lifted: SetLiftValue<Elements[number]> =
typeof value === 'symbol'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

das ist too specific imho - also du musst hier davon ausgehen dass es wenn es noch kein set lift hat, keine Unterscheidung auf dem.. Wert stattfinden muss? also du willst hier ja eigentlich checkne ob das value atomar ist oder nicht. Aber für dich sind alle Werte die du da kriegst schon atomar sonst muss man komplexer kodieren was es schon "partially" als set lift gibt etc. und braucht einen anderen constructor

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wenn ich hier aber nur atomare Werte annehme kann ich in der create function nicht mehr this mit "as this" zurückgeben, weil ich da ja eine instanz von SetLiftDomain mit einem Set als value erstelle

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

das ollte schon gehen tbh man kann das ja guarden und dann casten in der Funktion. Also ich finds ok als restriction die iwr aber mit der Zeit entfernen wollen

Comment thread src/taint-analysis/set-lift-domain.ts Outdated

protected equalsValue(this: SetLiftDomain<Top, Bottom, Elements>, other: SetLiftDomain<Top, Bottom, Elements>): boolean {
return this.value.size === other.value.size
&& [...this.value].every(element => other.value.has(element));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

du kannst eig bei sets .intersect usw. checken! auch symmetric differnces usw.

Comment thread src/taint-analysis/set-lift-domain.ts Outdated
isValue(): this is this & AbstractDomain<SetLiftValue<Elements[number]>, SetLiftTop<Elements[number]>, SetLiftBottom<Elements[number]>, SetLiftValue<Elements[number]>> {
// return !this.isBottom() && !this.isTop(); //Linter does not like this
return !(this.isSingletonEqual(this.base.baseBottom.value) || this.value.size === 0)
&& !(this.isSingletonEqual(this.base.baseTop.value) || this.isFullSet(this.value));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

das wirkt noch ein wenig umständlich aber von der Umsetzung sollte es korrekt sein :)

const E = Symbol('E');
const F = Symbol('F');

const lattice = new FiniteDomainBuilder() // Top

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for later: this sis genrally something where we probably wnat mutation tets because this can be systematizied


export const securityDomainLifted = securityDomain.setLift();

export const UserInputLifted = securityDomainLifted.create(UserInput).value;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this is a monadic set structure I am not so sure whether

  1. we want the .value access I'd expect that to be transparent
  2. we need the re-creation. I mean yes for tests against the actual underlying representation thats fine but we should mostly test on the scope of the lattice equality

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to be clear - you mean this in the sense of:

  1. using .equals instead of comparing the values directly in the tests (or completely disallowing .value accesses)
  2. mostly copied this from the existing security-analysis.ts but we can discuss how i could refactor my new and the existing tests :D

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :D

? BottomLifted
: taints.length > 0 ? AbstractDomain.joinAll(taints).value : TopLifted;

export const securityAnalysisLifted = TaintAnalysisDefinition.create('security', securityDomainLifted)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so technically the idea would be to not duplicate all of this.
but either have a securityAnalysis.backing(securityDomainLifted)
or to propagate it to lift. Like the implementation(s) of the analysis should be the exact same no matter whether we lift the structure or not.
Theoretically it should also be able to (dep injection style) lift them only when doing the actual analysis!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the sense of providing another method like .lift() on the analysis itself, that lifts its domain to a SetLiftDomain and adjust all conditionFn and taints to its corresponding lifted counterparts
OR
should analyses be defined in a way that is agnostic about the lift state of its domain? e.g. taints and conditionFn should not need any adjustment when lifting the domain

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes :P
the anlysis should be agnostic of whether they are lifted (or embedded to a sublattice etc.) and I also want a .lift on the lattice which makes the analysis treats it like a set

@@ -24,7 +24,7 @@ export const securityDomain = new FiniteDomainBuilder<Top, Bottom, [Top, Bottom,
.build();

/** Matches network protocols in a path argument. */
const NetworkProtocolRegex = /^(https?|ftps?):\/\//;
export const NetworkProtocolRegex = /^(https?|ftps?):\/\//;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: this should go as well. Not necessarily in this issue. But we have the network linting rule and by extend the input classifier which has a regex like this... Just much more sensitive :D

await testTaintAnalysis(code, securityAnalysisLifted, expectation);
});
}
describe('Lifted Security Taint Analysis', () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for these, also check out the input-classifier tests that we have in flowR!

@@ -16,7 +16,7 @@ import type { MultiValueDomain } from '../../../src/abstract-interpretation/doma
import type { TaintProduct } from '../../../src/taint-analysis/taint-visitor';
import type { TaintAnalysisBuilder } from '../../../src/taint-analysis/builder/taint-analysis';

export type TaintAnalysisExpectation = Record<SlicingCriterion, symbol | undefined>;
export type TaintAnalysisExpectation = Record<SlicingCriterion, symbol | undefined>; // | Set<symbol>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why comment out?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanted to leave this as a hint that i want to add it - but adding this will needs some more minor adjustments :D

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants