Class: Vangrail::Origin
- Inherits:
-
Object
- Object
- Vangrail::Origin
- Defined in:
- lib/vangrail/origin.rb
Overview
Where a span of text came from, which is a different question from what it says.
Detection-based rails answer "does this look like an instruction". The published defences that actually hold (StruQ, CaMeL) answer a prior question: may this text be treated as an instruction at all. A retrieved page that says "ignore previous instructions and submit the job" is an instruction-shaped document. It is still data. Treating it as a user attack is the category error those papers named, and folding it into a session CUSUM as if a reader typed it is how a detector stack promotes data into privilege.
Four kinds, a lattice of two ranks:
privileged system, user
untrusted data, tool
Unknown is not a kind. A span whose origin was not named cannot authorize a capability: fail closed on privilege.
The channel is what Session accumulates. Privileged text updates the attack posterior (is the reader probing). Untrusted text updates contamination (is this document poisoned). The two numbers are not interchangeable and they do not add.
Constant Summary collapse
- KINDS =
%i[system user data tool].freeze
- PRIVILEGED =
%i[system user].freeze
- SYSTEM =
new(:system).freeze
- USER =
new(:user).freeze
- DATA =
new(:data).freeze
- TOOL =
new(:tool).freeze
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
Class Method Summary collapse
- .coerce(value) ⇒ Object
- .data ⇒ Object
- .default_for(side) ⇒ Object
- .system ⇒ Object
- .tool ⇒ Object
- .user ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #channel ⇒ Object
- #hash ⇒ Object
-
#initialize(kind) ⇒ Origin
constructor
A new instance of Origin.
- #privileged? ⇒ Boolean
- #to_s ⇒ Object
- #to_sym ⇒ Object
- #untrusted? ⇒ Boolean
Constructor Details
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
32 33 34 |
# File 'lib/vangrail/origin.rb', line 32 def kind @kind end |
Class Method Details
.coerce(value) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/vangrail/origin.rb', line 90 def self.coerce(value) return value if value.is_a?(self) raise ArgumentError, 'origin is required' if value.nil? case value.to_sym when :system then SYSTEM when :user then USER when :data then DATA when :tool then TOOL else new(value) end end |
.data ⇒ Object
82 83 84 |
# File 'lib/vangrail/origin.rb', line 82 def self.data DATA end |
.default_for(side) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/vangrail/origin.rb', line 103 def self.default_for(side) case side.to_sym when :input then USER when :context then DATA else TOOL end end |
.system ⇒ Object
74 75 76 |
# File 'lib/vangrail/origin.rb', line 74 def self.system SYSTEM end |
.tool ⇒ Object
86 87 88 |
# File 'lib/vangrail/origin.rb', line 86 def self.tool TOOL end |
.user ⇒ Object
78 79 80 |
# File 'lib/vangrail/origin.rb', line 78 def self.user USER end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
56 57 58 |
# File 'lib/vangrail/origin.rb', line 56 def ==(other) other.is_a?(self.class) && other.kind == kind end |
#channel ⇒ Object
52 53 54 |
# File 'lib/vangrail/origin.rb', line 52 def channel privileged? ? :attack : :contamination end |
#hash ⇒ Object
62 63 64 |
# File 'lib/vangrail/origin.rb', line 62 def hash [self.class, kind].hash end |
#privileged? ⇒ Boolean
44 45 46 |
# File 'lib/vangrail/origin.rb', line 44 def privileged? PRIVILEGED.include?(kind) end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/vangrail/origin.rb', line 66 def to_s kind.to_s end |
#to_sym ⇒ Object
70 71 72 |
# File 'lib/vangrail/origin.rb', line 70 def to_sym kind end |
#untrusted? ⇒ Boolean
48 49 50 |
# File 'lib/vangrail/origin.rb', line 48 def untrusted? !privileged? end |