Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package example;

import base.RuleSample;
import base.RuleSet;

/**
* Doc validation: pattern-not-inside excludes when the positively produced
* client is the receiver of the safe-configuration call.
*/
@RuleSet("example/AllowlistNotInsideDoc.yaml")
public abstract class AllowlistNotInsideDoc implements RuleSample {

static class Client {
static Client builder() { return new Client(); }
void allowHost(String host) {}
void connect(String url) {}
}

static class Positive extends AllowlistNotInsideDoc {
@Override
public void entrypoint() {
Client c = Client.builder();
c.connect("http://example.com");
}
}

static class Negative extends AllowlistNotInsideDoc {
@Override
public void entrypoint() {
Client c = Client.builder();
c.allowHost("trusted.example");
c.connect("http://example.com");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package example;

import base.RuleSample;
import base.RuleSet;

/**
* Doc validation sanity probe: the same argument-position check event used in
* the negative probes, but required POSITIVELY. If this matches, the event
* exists as an automaton step and the negative failures are specific to
* negative clauses.
*/
@RuleSet("example/ArgEventSanityDoc.yaml")
public abstract class ArgEventSanityDoc implements RuleSample {

static Object decode(Object o) { return o; }
static int checksum;

static void check(Object o) { checksum += o.hashCode(); }
static void consume(Object o) {}

static class Positive extends ArgEventSanityDoc {
@Override
public void entrypoint() {
Object r = decode("x");
check(r);
consume(r);
}
}

static class Negative extends ArgEventSanityDoc {
@Override
public void entrypoint() {
Object r = decode("x");
consume(r);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package example;

import base.RuleSample;
import base.RuleSet;

/**
* Doc validation: full-form pattern-not whose added event uses the produced
* value in argument position does not anchor the exclusion — while the
* identical event matches positively (see ArgEventSanityDoc).
*/
@RuleSet("example/ArgFullPatternNotDoc.yaml")
public abstract class ArgFullPatternNotDoc implements RuleSample {

static String decode(Object o) { return String.valueOf(o); }
static int checksum;

static void check(String o) { checksum += o.hashCode(); }
static void consume(String o) {}

static class Positive extends ArgFullPatternNotDoc {
@Override
public void entrypoint() {
String r = decode("x");
consume(r);
}
}

static class Negative extends ArgFullPatternNotDoc {
@Override
public void entrypoint() {
String r = decode("x");
check(r);
consume(r);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package example;

import base.RuleSample;
import base.RuleSet;

/**
* Doc validation: argument-position pattern-not-inside does not anchor even
* with a satisfiable containment — the producer lives in pattern-inside and
* the main pattern is the single consume event, so the excluded context can
* enclose the match, yet the exclusion still has no effect. Contrast with
* ReceiverNotInsideSpanDoc, where a receiver-position exclusion works even
* when the context cannot contain the producing event.
*/
@RuleSet("example/ArgNotInsideAnchoredDoc.yaml")
public abstract class ArgNotInsideAnchoredDoc implements RuleSample {

static String decode(Object o) { return String.valueOf(o); }
static int checksum;

static void check(String o) { checksum += o.hashCode(); }
static void consume(String o) {}

static class Positive extends ArgNotInsideAnchoredDoc {
@Override
public void entrypoint() {
String r = decode("x");
consume(r);
}
}

static class Negative extends ArgNotInsideAnchoredDoc {
@Override
public void entrypoint() {
String r = decode("x");
check(r);
consume(r);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package example;

import base.RuleSample;
import base.RuleSet;

/**
* Doc validation: documents the current argument-position restriction: an
* excluded event that uses the produced value only as a call argument does
* not yet anchor the exclusion.
*/
@RuleSet("example/ArgObserverPatternNotDoc.yaml")
public abstract class ArgObserverPatternNotDoc implements RuleSample {

static String decode(Object o) { return String.valueOf(o); }
static void check(String o) {}
static void consume(String o) {}

static class Positive extends ArgObserverPatternNotDoc {
@Override
public void entrypoint() {
String r = decode("x");
consume(r);
}
}

static class Negative extends ArgObserverPatternNotDoc {
@Override
public void entrypoint() {
String r = decode("x");
check(r);
consume(r);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package example;

import base.RuleSample;
import base.RuleSet;

@RuleSet("example/ObjectParameterControlDoc.yaml")
public abstract class ObjectParameterControlDoc implements RuleSample {
static class Payload {}

Payload src() { return new Payload(); }
void clean(Object data) {} // parameter widened to Object
void sink(Payload data) {}

final static class PositiveSimple extends ObjectParameterControlDoc {
@Override
public void entrypoint() {
Payload data = src();
sink(data);
}
}

final static class NegativeSimple extends ObjectParameterControlDoc {
@Override
public void entrypoint() {
Payload data = src();
clean(data);
sink(data);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package example;

import base.RuleSample;
import base.RuleSet;

@RuleSet("example/ObjectTypedValueCastDoc.yaml")
public abstract class ObjectTypedValueCastDoc implements RuleSample {
static class Payload {}

Object src() { return new Payload(); } // value's static type is Object
void clean(Payload data) {}
void sink(Object data) {}

final static class PositiveSimple extends ObjectTypedValueCastDoc {
@Override
public void entrypoint() {
Object data = src();
sink(data);
}
}

final static class NegativeSimple extends ObjectTypedValueCastDoc {
@Override
public void entrypoint() {
Object data = src();
clean((Payload) data);
sink(data);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package example;

import base.RuleSample;
import base.RuleSet;

@RuleSet("example/ObjectTypedValueDoc.yaml")
public abstract class ObjectTypedValueDoc implements RuleSample {
Object src() { return null; }
void clean(Object data) {}
void sink(Object data) {}

final static class PositiveSimple extends ObjectTypedValueDoc {
@Override
public void entrypoint() {
Object data = src();
sink(data);
}
}

final static class NegativeSimple extends ObjectTypedValueDoc {
@Override
public void entrypoint() {
Object data = src();
clean(data);
sink(data);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package example;

import base.RuleSample;
import base.RuleSet;

@RuleSet("example/ObjectTypedValueReceiverDoc.yaml")
public abstract class ObjectTypedValueReceiverDoc implements RuleSample {
Object src() { return null; }
void sink(Object data) {}

final static class PositiveSimple extends ObjectTypedValueReceiverDoc {
@Override
public void entrypoint() {
Object data = src();
sink(data);
}
}

final static class NegativeSimple extends ObjectTypedValueReceiverDoc {
@Override
public void entrypoint() {
Object data = src();
data = data.toString();
sink(data);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package example;

import base.RuleSample;
import base.RuleSet;

/**
* Doc validation: multi-event pattern-not where the excluded on-path event is
* a receiver call on the produced value.
*/
@RuleSet("example/ReceiverSanitizePatternNotDoc.yaml")
public abstract class ReceiverSanitizePatternNotDoc implements RuleSample {

static class Value {
Value sanitized() { return this; }
}

static Value decode(Object o) { return new Value(); }
static void consume(Value v) {}

static class Positive extends ReceiverSanitizePatternNotDoc {
@Override
public void entrypoint() {
Value r = decode("x");
consume(r);
}
}

static class Negative extends ReceiverSanitizePatternNotDoc {
@Override
public void entrypoint() {
Value r = decode("x");
r = r.sanitized();
consume(r);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package example;

import base.RuleSample;
import base.RuleSet;

/**
* Doc validation sanity probe: the self-sanitizing reassignment event
* required POSITIVELY. If this matches, the event exists as an automaton
* step and the negative failures for the same event are specific to
* negative clauses.
*/
@RuleSet("example/SanitizeEventSanityDoc.yaml")
public abstract class SanitizeEventSanityDoc implements RuleSample {

static Object decode(Object o) { return o; }
static Object sanitize(Object o) { return o; }
static void consume(Object o) {}

static class Positive extends SanitizeEventSanityDoc {
@Override
public void entrypoint() {
Object r = decode("x");
r = sanitize(r);
consume(r);
}
}

static class Negative extends SanitizeEventSanityDoc {
@Override
public void entrypoint() {
Object r = decode("x");
consume(r);
}
}
}
Loading
Loading