Repository navigation
fix(tier3): mask five more credential forms in security finding evidence - #562
Conversation
Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Follow-up to #445. Security finding evidence kept the credential in these command forms: - An assignment value read as a parenthesized tuple only when it started with "(", so auth=HTTPBasicAuth('bob', PASSWORD) masked only the class name. A dotted call name may now start the value, and the arguments of a call or tuple may hold one level of calls. A call is read only when its ")" ends the word, so a word with parentheses in it is still masked whole. - A credential name right after "/" was read as a URL host or path segment, so sed -i 's/password=.*/password=NEW/' kept NEW. A name may now start the pattern or the replacement of a sed s/PATTERN/REPLACEMENT/ expression whose "s" starts a word; a /s/ URL path segment is not one. - A long flag name was read as letters, digits and "-", so --db_password, --api_key and --auth_token kept their values. Flag names may now hold "_", also in the short -api_key form and in argv lists; a name ending in _file, _path, _dir, _jar or _stdin still keeps the word after it, and --max_tokens and --token_limit keep their numbers. - The config set key had to be an unquoted word after the options, so a quoted key or one after "--" kept its value. Both forms are now read; the quotes stay out of the key that is checked for a credential word. - A shell apply_patch command was cut to 400 characters before it was masked, so a cut inside URL user info left a password no pattern recognized. The text is now masked first and then cut. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…written file Follow-up to #445. A sensitive-path or sensitive-file-write finding recorded only the longest protected entry found anywhere in the command. That rule was meant for nested entries (/etc/profile.d over /etc/profile), but with unrelated entries it dropped one the command touched: tar czf k.tgz ~/.ssh ~/.aws/credentials recorded only .aws/credentials, and against a baseline that read only ~/.aws/credentials the with-skill finding was attributed to the baseline. A command still gets one finding per check, and its evidence now lists every matched entry in list order, such as "~/.ssh, .aws/credentials". When several entries match, each path word is read on its own, and an entry that is part of a longer entry in that word, as written or with its home spelled "~", is left out, so /etc/profile.d/npm.sh records /etc/profile.d and /root/.ssh/id_rsa records /root/.ssh. A command with one matched entry is read as before. The baseline comparison then compares the whole list. A shell write finding also took the longest entry across the keyword rule and the write targets, so grep -h umask /etc/profile >> ~/.bashrc recorded the /etc/profile it only reads. The finding now lists the protected files its redirection, tee or sed -i targets write, and only when no target names one does it record the keyword rule's entry. The keyword rule itself, and which commands get a finding, are unchanged. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…all forms Follow-up to #445. Three gaps in the credential masking of security finding evidence: - A value read as a call ended at its ")" when "," ")" "]" or "}" came next, and the call reading was tried before the word reading. A word with parentheses in it was then cut short: "password: Pa(ss),word" kept ",word", and "PASS=Ab(c)}..." kept the text after "}". The call reading is now used only when it runs past the word read from the same start, so such a word is masked whole again, while "auth=HTTPBasicAuth('svc', PASSWORD), timeout=5" still keeps ", timeout=5". - In an ssh, sh -c or eval command string, or a perl -e program, a value is one word, so in "s/token: .*/token: NEW/" the value of the name that starts the pattern ran over the name that starts the replacement, which was then skipped and NEW was kept. When a value runs over a sed replacement name, the masked text now runs on to the end of that name's value. - A call whose arguments a formatter split over lines, as in "session.auth = HTTPBasicAuth(\n \"svc\", PASSWORD\n)", kept the password. A call's arguments may now span lines; a tuple's still may not. The docs and CHANGELOG also say that flags naming a token other than --max-tokens and --token-limit, such as --max_new_tokens, are masked in either spelling. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… drop Follow-up to #445. A shell sensitive-file-write finding listed the files its redirection, tee or sed -i targets name, and only when no target named one did it record the keyword rule's entry, and then only the longest. That rule flags a command that names a shell startup or sudoers file and has a redirection anywhere, and it is the only one that sees a file written by cp, mv, install or dd. So: - "sudo cp evil /etc/sudoers.d/x && cp evil2 ~/.bashrc 2>/dev/null" recorded only /etc/sudoers.d, and was attributed to a without-skill baseline that wrote only /etc/sudoers.d. - "cp /tmp/evil /etc/sudoers.d/agent && echo x >> ~/.bashrc" recorded only ~/.bashrc, so the sudoers write was attributed to a baseline that appended to ~/.bashrc. The keyword rule now lists every entry it finds, leaving out one that is part of a longer entry in the same path word, as the path findings do. Its entries are the evidence when no target names a protected file, and are listed beside the target entries when the command also runs a command that writes a file named in its arguments (cp, mv, install, dd, ln, rsync, scp, curl, wget, tar, unzip) or an interpreter. A file the command only reads beside a redirection, as in "grep umask /etc/profile >> ~/.bashrc", is still left out. Which commands get a finding is unchanged. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
An apply_patch write finding recorded only the first protected file header, so a patch that added ~/.bashrc and ~/.ssh/authorized_keys recorded ~/.bashrc and was attributed to a baseline that wrote ~/.bashrc alone. The finding now lists the entry of every protected header in a fixed order, as shell command and tool path findings do. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd similar commands A shell write finding lists the keyword rule entries beside its redirection, tee or sed -i targets only when the command runs a command that writes a file named in its arguments. visudo, ed, ex, truncate, patch, sponge, sort -o and awk were not among them, so "visudo -f /etc/sudoers.d/agent && echo y >> ~/.bashrc" recorded only ~/.bashrc and was attributed to a baseline that wrote ~/.bashrc. These commands are now read as writers, as cp and the interpreters are, so the sudoers or profile entry is listed again. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…osing quote A credential name that starts a sed pattern masks the rest of the quoted expression, and a credential name inside that masked value was skipped unless it started the replacement. When the replacement splices its value in after the closing quote, as in s/TOKEN=.*/export TOKEN='"VALUE"'/, the skipped name's value was left in the evidence, where it was masked before sed pattern names were read. Any credential name inside the value of a name in a sed expression now extends the masked text to the end of its own value. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed config values Reading "_" in credential flag names and "--" before a config key let the flag and config set rules take over forms the assignment rule masked better. "--api_key=K1;TOKEN=..." ran the flag value over the next assignment and left its quoted value, "--auth_token=(..., VALUE)" masked only the opening parenthesis, and "npm config set -- password = VALUE" masked only the "=". A "_" flag joined to its value with "=" is now left to the assignment rule, an unquoted value after a "_" flag and a space ends at ";", "|" or "&" as an assignment word does, and a config set rule no longer takes a separator word as the value, so the assignment rule masks "password = VALUE" in every spelling. Flags spelled with "-" are unchanged. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
The shell write rule lists the keyword rule entries beside its targets when the command runs patch. The "*** Begin Patch" line of a shell apply_patch heredoc matched that word, so a protected file that the patch body only mentioned was listed beside the file a redirection wrote. The envelope lines no longer count as a patch command. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
This reverts the path-evidence listing added by 0ea994e, 26f3f82, e493f80, f3491c9 and 124d97e. A sensitive-path or sensitive-file-write finding again records the longest protected entry its command, path or apply_patch header names, and the baseline comparison again matches that one entry, as the Tier 3 docs describe. Their docs, CHANGELOG text and tests go with them. The credential masking fixes on this branch are unchanged. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the assignment rule The assignment rule reads past a separator, so main masks the value in "./tool --api_key = VALUE" and "npm config set -- password ='VALUE'". Reading "_" flag names, and quoted or "--" config keys, with the flag and config rules made those rules take the separator for the value, so the value stayed in the evidence. "--api_key = VALUE" became "--api_key <redacted> VALUE", also with " : ", " := " and " => ", in the short "-access_token := VALUE" form, with a quoted value and inside a quoted string. The config rule masked only the separator in "npm config set -- password ='VALUE'", 'npm config set "password" ="VALUE"' and "yarn config set -- GITHUB_TOKEN :'VALUE'". A "_" flag followed by a separator is now left to the assignment rule, as one joined to its value with "=" already was. After a quoted key or a key after "--", the config rule no longer takes a value that starts with a separator. An unquoted key keeps the reading it has on main. New guards pin the eight forms on the shared checks and the Harbor template. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…expression When the masked value of a name in a sed expression ran over other credential names, each of them was read again so that a value spliced in after a closing quote is still masked. A long one-word value made that quadratic: masking judge evidence, which has no 2,000-character cut, took about 2.4 s for "sed -i 's/password=" followed by 36,000 characters of "x,token=y", and 0.014 s on main. A name inside a masked value is now read again only while the masked text ends inside the sed expression that holds it: the expression whose pattern or replacement the name starts, or else the one whose name's value this is. Each part of an expression is read up to 256 characters, as the sed pattern rule already reads it. A value spliced in after the closing quote of the replacement is still masked, also after an anchored pattern such as "s/^password=.*/password='"NEW"'/", and the same input now takes 0.017 s. A test counts the credential names the masker checks and pins that the count does not grow with the length of the value. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…read Reading a name in a masked sed value again only inside its expression kept masking linear, but each part of the expression is read up to 256 characters, so a name further on was no longer read. Its value then stayed where main masks it: in "sed -i 's/TOKEN=.*/export <300 characters> TOKEN='"VALUE"'/'", the value of the pattern name ends at the closing quote, and the VALUE spliced in after it was kept. So was the same splice after a pattern longer than 256 characters. A name that starts no sed pattern or replacement is now also read whenever no value read for such a name holds it, as it is when no sed expression is read. Those values do not overlap, so masking stays linear. Guards pin the three forms on the shared checks and the Harbor template's judge evidence. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
A quoted npm, yarn or git config key, or one after "--", was read with the flag value, whose unquoted word runs over ";", "|" and "&". So in npm config set -- password K1;TOKEN="..." the value took "K1;TOKEN=" and the quoted value after it stayed in the evidence, although the assignment rule masked it before those keys were read. The unquoted value of such a key now ends at ";", "|" or "&", as a "_" flag value does. An unquoted key keeps its reading. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the assignment rule A "_" flag value, and the value of a quoted config key or one after "--", is read as one word that ends at a quote. When that word was itself an assignment, as in --set_secret API_TOKEN="...", the flag or config rule masked only "API_TOKEN=" and removed the name the assignment rule read before these forms were read, so the quoted value after it stayed. The same happened for a name later in the word (--api_key K1,TOKEN="..."), a name before a spaced separator (--api_key TOKEN = ...), a quoted value that holds a name whose value follows it, and a name that follows the value with no space. Such a value is now left to the assignment rule, which masks it as it did before. A value with no credential name in it is still masked whole. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ord again A call value is read to its first ")" and a tuple value may hold a call, so such a value could run over a credential name that was read before, and that name was then skipped as part of the masked value. When that name had a quoted value with a ")" in it, as in auth=f(u, password="a) b"), or a value glued after a tuple, as in apikey=(()TOKEN=)VALUE, the rest of its value stayed. A credential name in a call value past its first word, or in a tuple value past its first parenthesis, is now read again, as it was before those values were read, and its value extends the masked text. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r again npm config set KEY = VALUE is read as an assignment, so VALUE is masked whole. The config rule used to mask only the separator, and the assignment rule then read each name in VALUE. When VALUE was read as one word that ended at a quote, as in npm config set _auth = token="...", the name in it was skipped as part of the masked value and its quoted value stayed. Each credential name in the value of such a key is now read again, so its value extends the masked text, as it did when the separator was masked as the value. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e assignment rule An argument list element after a "_" flag is read as the flag value, as on the command line. When that element held a credential name with an empty value and the value was glued after it, as in ["tool", "--db_password", "passwd:""..."], the element was masked and the glued value stayed, although the assignment rule masked it before "_" flags were read. Such an element is now left to the assignment rule, as a "_" flag value on the command line is. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l name is an assignment The docs and CHANGELOG said only an unquoted value after a "_" flag or a quoted or "--" config key is read as an assignment when it holds a credential name. A quoted value of such a flag or key is read that way too, so say so. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
npm config set KEY = VALUE is read as an assignment. When KEY names a credential, the config set rule used to mask only the separator, and the assignment rule then read names from the word after it. When that word is an auth scheme word, such as token, the assignment rule now read it as part of the name KEY = token, so in npm config set _authToken = token = "..." only the second = was masked and the quoted value stayed. The same held for :=, : and => after the scheme word. Names after it were also read from a different word than before, so a later name could be skipped. Names are now read from the word after the separator of such a KEY, as they were when only the separator was masked: an auth scheme word there starts a name of its own, whose value is masked too. Only a key that names a credential is read this way, as only its separator was masked. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…does A _ flag that names a credential is read like its - spelling, so the word after one that takes no value, such as --skip_token_check, is masked as its value. When that word starts a command another rule reads, such as mysql -p, sshpass -p, aws configure set, a .netrc login, npm config set or git config, that command is read as it is after the - spelling. The test checks that both spellings give the same evidence. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
rng1995
left a comment
There was a problem hiding this comment.
Checked the five new masked forms: auth= call values, names inside sed substitutions, long flags spelled with _, quoted or -- config keys with = values, and apply_patch text masked before the 400-character cut. The apply_patch fix and the config-key forms hold up, the new apply_patch test fails on main as it should, and the staged checks still import and run under Python 3.9. Two problems: a value-less _ flag now takes the next command word as its value, which hides that command from the rules that mask its password (main masked ./wrap --use_token mysql -u root -pS3cret db), and the call and tuple readings still leak a quoted argument that holds a parenthesis.
Findings: 2 P2, 1 P3.
Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hole
A call or tuple value read every "(" and ")" as call syntax, even inside a
quoted argument, so a password with a parenthesis in it leaked:
'auth=HTTPBasicAuth("bob", "pa)ss"))' fell back to the word
"HTTPBasicAuth(", 'auth=HTTPBasicAuth("bob", "pa(ss")' at the end of a line
did too, and 'auth=("bob", "pa)ss")' stopped at the ")" inside the string.
A tuple or call value is now also read with each JSON-escaped, double- or
single-quoted argument that closes on its line read whole, and that reading
is used when it runs past the earlier one, so every value masked before is
still masked. A call whose quoted argument holds a ")" now ends at its own
")" instead of masking the ")" after it.
Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uns past it The value of a "_" flag, or of a quoted config key or one after "--", was left to the assignment rule whenever it held a credential name. That rule skips location, type and count names and a bare PASS with a number, so "--set_secret SLACK_TOKEN_URL=https://...", "--api_key auth_type=VALUE" and "--db_password PASS=1234" were kept in full, also as an argv element and as the value of "npm config set -- _authToken". When the rule did mask, a name whose value ended inside the flag value left the text before it: "--db_password VALUE,token=x" kept VALUE. The value is now left to the assignment rule only when that rule masks the value of a credential name in it past the value's end, as in '--set_secret API_TOKEN="..."'. Any other value is masked whole, as after the "-" spelling or an unquoted key. Each name is read on its own, as the assignment rule reads it: the rule's choice of how to read a value moves into _assignment_value_reading and _assignment_name_is_kept, which the rule and the new _AssignmentValues share. _AssignmentValues is made per text, so nothing is kept between calls. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
A config set command that starts a line after a "\n", "\r" or "\t"
escape ("db\nnpm config set _auth = token=\"VALUE\"") was not read,
because the escape's letter joined its first word. The assignment rule
then masked only "token=" as the value of "_auth = ", so the quoted value
after it stayed in finding and judge evidence, also when another value
on the same line was masked. The command word may now follow such an
escape.
Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…erator
Inside a quoted string the value of a config set key after a separator
word ("npm config set _auth = VALUE") was read to the closing quote, also
over "&&" and the commands after it. In a Python string such as
os.system('npm config set _auth = token="..." && mysql -u root
-p\'VALUE\' db') that read ended at the escaped quote before the MySQL
password, which the MySQL rule then no longer read, so the password stayed
in finding and judge evidence. That value now also ends at a shell
operator and at an escaped quote, and the spaces before them.
Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Text escaped again is also read with one and two levels of escapes
removed, and what a reading masks is mapped back to the text by the text
kept between its markers. Where that kept text fits the reading in more
than one place, nothing was masked for the markers around it. So a
docker login password after a decoy "-p" in an earlier flag value
(--token "x -p y" -p VALUE) stayed in a tool call escaped twice, as in a
RAGAS prompt, and so did the arguments of a spaced call value
(session.auth = HTTPBasicAuth("bob", "VALUE")) with the same flag twice
after it. Such a marker now masks everything from where the kept text
before it ends at the earliest to where the kept text after it starts at
the latest.
Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A credential name whose value starts with an escaped single quote, as in
Python source (os.system('export DB_PASSWORD=\'two words\' && ./deploy')),
kept the words after the first one in finding and judge evidence. The
assignment rule now reads such a value to its escaped closing quote, as
it reads a value in JSON-escaped double quotes. A "_" flag value that
holds such a name ("--auth_token API_KEY=\'two words\'") is left to that
rule, as one that holds a name whose value runs past the flag word is,
so the words after the first one are no longer kept there either.
The test that masks masked text again now also masks texts the tests
build from their parameters, and checks that a second pass shows
nothing more and masks only text right after a marker: it may read a
marker as the start of a value and mask the text after it, as it does
for the rest of a quoted string or the word after a "\n" escape.
Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Inside a single-quoted command string (ssh host '...', bash -c '...') a value is quoted with the '"'"' or '\'' idiom, which closes that string, writes a quote and opens it again. The flag rule read only the first three characters of the idiom as the value, so the words of --password '"'"'two words'"'"' were kept, also after sshpass -p and the other rules that read a flag value, and the quotes after it were read out of step. A call value later in the string (client.auth=HTTPDigestAuth(...)) then read as inside a double-quoted string, so only its first word was masked. Such a value now runs to the next idiom or the end of the line. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
A "_" flag or quoted config value is left to the assignment rule when a
name in it has a value that runs past it, so every name in the value was
read with the assignment rule's full reading, and the quotes of the whole
text were read first. On a 1 MB word with 100,000 names in it
("--db_password a\ -token=a\ -token=a...") that took about eight times as
long as the masker took without reading "_" flags.
A name inside an unquoted word that "=" joins to a value starting as a word
and no call reads the rest of that same word, so it is no longer read. No
name is looked for past the last "=" or ":" of the value, the quotes are
read only as far as a position asked for, and the names a masked value may
hide are found only once a masked value hides a credential. That shape now
takes about four times as long as without the "_" flag reading, and a long
word after a few names about three times.
Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A credential name that starts a part of a sed expression inside a JSON
string ({"command": "sed -i 's/token_count: .*/token_count: 4096/' cfg.yml
&& rm -rf /srv/app"}) read its value as the rest of that string, past the
shell quote that closes the expression, so finding and judge evidence lost
the command after it, also after a line continuation. A value read as the
rest of a quoted string now ends with the sed expression its name starts a
part of, when that expression ends with its closing "/". The sed flags
after that "/" are kept ("s/__TOKEN__/token=<redacted>g").
Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Judge evidence that holds a NUL character is not read again with its escapes removed, so only the line pass of the Harbor verifier masks the rest of a line after a "_" flag value that the whole pass left to the assignment rule. The line-start test now also runs with a NUL in the text, and fails when that line pass reads such a line as it did before. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
This reverts commit 5421da7. Ending the value there kept the command after a sed expression inside a JSON string, but the rest of that string also holds credentials in forms no rule reads, which the longer value masked: a sed placeholder replacement ("s/PASSWORD/VALUE/"), a backreference before "=" ("s/^\(client_secret\)=.*/\1=VALUE/"), a here-string after --password-stdin. On a corpus of 140,000 generated commands, about 120 to 240 more such values per evidence kind were kept. The value of such a name runs to the end of the quoted string again. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…whole A credential name in a single-quoted command string whose value is quoted with the '"'"' or '\'' idiom (bash -c 'export DB_PASSWORD='"'"'two words'"'"' && ...') was read as an empty value that the idiom's first quote closes, so only the idiom's middle was masked and the words of the value were kept. Such a value is now read to the next idiom, as a flag value is. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Inside a single-quoted command string, an attached MySQL password quoted with the '"'"' or '\'' idiom (bash -c 'mysql -u root -p'"'"'VALUE'"'"' db') had only the idiom's middle masked, so the password was kept. It is now read to the next idiom, as a flag value is. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ted text State that a config set command may follow a "\n", "\r" or "\t" escape, that a quoted config value after a separator ends at a shell operator or an escaped quote, and that values in escaped single quotes or quoted with the '"'"' or '\'' idiom are masked whole. Narrow the sentence on a password after a flag value that holds a "-p" or ";" to credential flag values, and the sed replacement form to the "/" delimiter. Add the forms that can still appear (a here-string password, a pip config set value, a sed replacement that names no credential or uses another delimiter in a command string, a mysql password after a ";" in another flag value, an auth= call quoted with nested idioms, a call value split over lines in JSON text) and the text masked when a reading's kept text fits more than one place or a sed name starts a value inside a JSON string. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
State the masking change in a few lines and leave the exact forms to the Tier 3 live evaluation guide. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Apply the formatter to the lines this branch changed, bind the call counter of the name-read test once outside its loop, and give the passwords of the spaced call test plain names. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
A flag inside the masked value of an earlier "_" flag is read so that the
rest of its own value past that value can be masked. When the earlier
value is an unquoted word that ends at whitespace, a quote, a backtick or
the end of the text, a flag inside it whose value starts there as a word
ends where that word ends, so it is no longer read. On a 1 MB word of
100,000 such flags ("--db_password a\ -token=a\ -token=a...") masking
took about 0.9 s and now takes about 0.7 s, against 0.22 s without the
"_" flag reading.
Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Verified addressed at fe2817a0. Independent validation confirmed that the interleaved CPU-time growth guard accepts the current implementation and rejects the deliberately quadratic control. The 1,121 evidence tests pass; matched local 500,000-character CPU measurements improved from 0.787 s on the prior head to 0.353 s on this head. This addresses this specific test-contract finding; overall CI/readiness remains a separate gate. Original review at b5d5f3b[P2] Make the new speed guard match its intended performance contract The new flag-masking guard at lines 2645–2647 measures one Matched, isolated local controls on the same 500,000 character input measured about 0.39–0.40 seconds on the recorded base and 0.85 seconds on this head. The head still scaled roughly 9x for 10x the input. That establishes additional work, but does not establish a nonlinear algorithm or prove the CI failure is a flake. Please make the assertion test the intended contract: if it is near-linear complexity as its comment says, use repeated/interleaved small-versus-large CPU-time measurements (like |
…appear
A credential name at the start of a line after a "\n" escape is read on
its own when an unquoted assignment value ran over it. When a flag or
config value runs over the escape, a tuple or call value on that line
(--password K1\nauth=("bob", "...")) keeps its arguments, so list it with
the forms that can still appear and narrow the sentence to assignments.
Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ction-followups Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Masking finding and judge evidence searched each whole text for each
command credential rule, the attached "-pVALUE" argv element and the
config set forms, several times per reading, also where the text holds
none of the words such a match needs ("login", "mysql", "sshpass",
"npm" and "config", ...). Those searches are now skipped, as are a
second read of the attached elements when no argv value is masked,
lookups in empty span indexes, a second match of each name in a flag's
word that ends before its last separator, and a search call per
assignment name: one finditer reads the names, starting again only
after a config set name. The masked text is the same.
On the 19 long-text shapes of the flag tests at 500,000 characters,
masking took 0.4 to 3.8 times as long as on main and now takes 0.3 to
2.4 times as long; the argv list in JSON before a long word went from
about 1.8 to 1.0 times.
Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The long-text flag test timed one masking of each text of 40,000 to 500,000 characters against a fixed two-second wall-clock limit, which depends on the runner's speed and load and does not test the near-linear growth its comment states. Each shape is now a function of the length, whose units grow in number with the text, and the test measures it with the escaped-again tests' _masking_seconds: 10,000 and 100,000 characters masked in turn, best of three, in thread CPU time with garbage collection paused, and the larger may take at most 16 times as long plus 0.05 s. The argv list before a long word now holds a flag per 2,500 characters, so a flag reading the word again grows with the square of the text. A control test runs the same measurement and bound on value-less flags in a quoted string of 3,000 and 30,000 characters, once as masking reads them and once with a reading that reads each word or quoted rest again from every name in it, and checks that the bound accepts the first and rejects the second. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ction-followups Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, addressed in fe2817a.
|
Summary
Follow-up to #445. On main, Tier 3 security finding evidence and saved judge evidence keep the credential in several command forms, a credential flag that takes no value can hide the password of the command after it, and shell
apply_patchevidence is cut before it is masked. This branch masks them in the shared checks (eval_core/checks.py), which the host checker and the bundled Harbor verifier both run, and in the Harbor template's judge line pass. Path finding evidence and its baseline matching are unchanged. The branch includes main 96f03c1. Against main it changes 6 files: the checks,templates/eval.py, two test files,docs/tier3-live-evaluation.mdxand one CHANGELOG bullet under Unreleased.Masking forms covered
auth=call values. Main masksauth=HTTPBasicAuth("bob", "...")andauth=requests.auth.HTTPDigestAuth(...)only up to the class name. A call value is now read to its), with one level of nested calls, arguments on several lines, and a(or)inside a quoted argument; a tuple (auth=("bob", "...")) is read the same way. A word with parentheses in it (Pa(ss),word) is still masked whole.sedsubstitutions. Main reads a credential name right after/as a URL path segment, sosed -i 's/password=.*/password=NEW/'keepsNEW. A name may now start the pattern or the replacement of ans/PATTERN/REPLACEMENT/expression, also inside anssh,sh -corevalstring, and a value spliced in after the closing quote is masked too._.--db_password VALUE,--api_key VALUE,-api_key VALUEand such argv elements are read like the-spelling. An unquoted value after such a flag ends at;,|or&. A value that holds a credential name whose value runs past it, is already masked, or is in escaped single quotes is left to the assignment rule, so masking masked text again keeps it.--innpm config set,yarn config setandgit configis read, also with JSON-escaped quotes, and the command may follow a\n,\ror\tescape. Inside a quoted string the value after a key and a separator word (npm config set _auth = ...) ends at the closing quote, a shell operator or an escaped quote.\nescape that an unquoted assignment value ran over is read on its own (API_TOKEN=a\nauth=("bob", "...")).--use-token mysql -u root -p...,docker login -p,sshpass -p,aws configure set, config set, or amysqlorloginargv element before an attached-p...), that command's password is masked too, also after a-por;inside a later credential flag value (--use_token docker login --token "x -p y" -p ...).'export DB_PASSWORD=\'two words\''), is read whole. Inside a single-quotedsshorsh -cstring, a flag, assignment or MySQL-pvalue quoted with the'"'"'or'\''idiom runs to the next idiom (ssh host './deploy --password '"'"'two words'"'"'').docker loginpassword after a decoy-p(--token "x -p y" -p VALUE) in a tool call escaped twice is masked.apply_patch. Shellapply_patchevidence is masked before its 400-character cut, so a cut inside URL user info no longer keeps part of the password.templates/eval.py). Inside a quoted string the whole-text pass can leave a_flag value to the assignment rule where the line on its own masks it whole; the line pass now also matches the rest of such a line without the word that ends at the next marker. Main's escaped readings mask the same values in most text, so this matters where they do not run, such as text that holds a NUL character.docs/tier3-live-evaluation.mdxlists the masked forms, the forms that can still appear and the ordinary text that is masked. The CHANGELOG bullet states the rule and points to the guide.Known gaps
sedreplacement that names no credential (s/PASSWORD/.../) or uses another delimiter inside a command string, a here-string after--password-stdin, apip config setvalue,redis-cli -a, amysqlpassword after a;inside a flag value that names no credential, anauth=call quoted with nested idioms, a tuple or call on the line after a\nescape that a flag or config value runs over (--password K1\nauth=("bob", "...")), a call value split over lines in JSON text, all but the first word of a value with spaces in ash -corsshstring, and JSON inside a Pythonrepr(\\")._flag value or quoted config value that holds a credential name is masked as main masks that name, so--api_key K1,TOKEN=...keepsK1. The unquoted value of a-flag still runs past;,|and&, as on main.-pabove); in a JSON string, the rest of the string after a credential name that starts asedexpression; and the value of a flag that names a token other than--max-tokensand--token-limit(--max_new_tokens 256), as in the-spelling.\nescape, closing brackets or quote characters.Timing
Judge evidence is masked whole, with no scan window, so the contract is that masking grows close to linearly with the text.
test_masking_credentials_behind_flags_grows_linearly_with_the_textchecks it on 19 text shapes that the flag rule and the readings it starts read (value-less flags before commands, names in long flag values, hidden passwords, names past masked values, flags inside long flag words, argv lists in JSON repeated as JSON, flags before a long word). Each shape is written at 10,000 and 100,000 characters, with its units growing in number with the text, and measured with_masking_seconds, as main's escaped-again tests are: the two texts masked in turn, best of three, in thread CPU time with garbage collection paused. The larger may take at most 16 times as long plus 0.05 s. There is no wall-clock limit.test_the_linear_growth_bound_rejects_reading_each_run_againruns the same measurement and bound on value-less flags in a quoted string of 3,000 and 30,000 characters, once as masking reads them and once with a reading that reads each word or quoted rest again from every name in it, and checks that the bound accepts the first and rejects the second (about 50 to 70 times as long), so the guard cannot pass vacuously.On
flags-before-a-long-wordat 500,000 characters (200 flags in an argv list before the long word), masking takes 0.44 s of CPU time on this head, 0.44 s on main 066d435 and 0.95 s on the previous head b5d5f3b (best of three, garbage collection paused); at 50,000 characters it takes 0.04 s on this head and on main. Across the 19 shapes at 500,000 characters, masking takes 0.3 to 2.4 times as long as on main.The time changes on this branch skip whole-text searches that cannot match (a command credential rule, the attached
-pVALUEargv element or a config set form in a text that lacks the words every match holds), a second read of the attached elements when no argv value is masked, lookups in empty span indexes, a second match of each name in a flag word that ends before its last separator, and a search call per assignment name. The masked text is the same: 70,152 texts (the strings the test modules pass, their random combinations and escapings, and token-level random commands) mask identically before and after, as finding evidence, with header formatting, cut finding evidence and judge evidence.Tests
tests/tier3/test_security_finding_evidence.py,tests/tier3/test_apply_patch_security.py,tests/tier3/test_judge_contracts.py,tests/tier3/test_verifier_python39_syntax.pyandtests/test_oss_packaging.py: 2593 passed, 1 failed. The failure,test_harbor_environment_kwarg_contract_matches_installed_source, also fails on main locally because the installed Harbor is older than main's pin.test_masking_escaped_again_stays_linear_on_adversarial_inputandtest_judge_evidence_masking_escaped_again_stays_linear_on_adversarial_input): 33 passed.git merge-tree --write-treeagainst it is clean.🤖 Generated with Claude Code