Read in your language | Plain text | JSON source
\n" 38 text trj1 "{\"source_url\":\"" 39 text trj2 "\",\"lang\":\"" 40 text trj3 "\",\"text\":\"" 41 text trj4 "\",\"html\":\"" 42 text trj5 "\"}\n" 43 text trcspnm "content-security-policy:" 44 text trscript "script-src" 45 text trnone "'none'" 46 text trcspbad "served response must have script-src 'none' without other script sources or overrides" 47 note trq: attribute value offset/length, depth, protected depth, explicit lang depth, raw depth. 48 global trq ulong 6 49 50 fn trat a ulong e ulong t view uchar * to bool 51 if gt add a len t e 52 ret false 53 end 54 ret mistf a t false 55 end 56 57 fn trname a ulong e ulong to ulong 58 k = a 59 while lt k e bound `9223372036854775807` 60 if not namechar mg k 61 break 62 end 63 k = add k 1 64 end 65 ret k 66 end 67 68 fn trtagend a ulong e ulong to ulong 69 q = uchar 0 70 k = a 71 while lt k e bound `9223372036854775807` 72 c = mg k 73 if ne q 0 74 if eq c q 75 q = 0 76 end 77 else 78 if or eq c 34 eq c 39 79 q = c 80 else 81 if eq c 62 82 ret add k 1 83 end 84 end 85 end 86 k = add k 1 87 end 88 die ermark 89 ret e 90 end 91 92 fn trget a ulong e ulong key view uchar * to bool 93 note Parse attributes, not substrings inside other attribute values. Markup has already been checked. 94 k = a 95 put trq 0 0 96 put trq 1 0 97 while lt k e bound `9223372036854775807` 98 if space mg k 99 k = add k 1 100 continue 101 end 102 s = k 103 k = trname k e 104 if eq s k 105 ret false 106 end 107 hit = mist s sub k s key 108 while lt k e bound `9223372036854775807` 109 if not space mg k 110 break 111 end 112 k = add k 1 113 end 114 if eq mg k 61 115 k = add k 1 116 while space mg k bound `9223372036854775807` 117 k = add k 1 118 end 119 q = mg k 120 k = add k 1 121 v = k 122 while lt k e bound `9223372036854775807` 123 if eq mg k q 124 break 125 end 126 k = add k 1 127 end 128 if hit 129 put trq 0 v 130 put trq 1 sub k v 131 ret true 132 end 133 k = add k 1 134 end 135 end 136 ret false 137 end 138 139 fn trclasses a ulong e ulong to bool 140 if not trget a e trclass 141 ret false 142 end 143 k = get trq 0 144 lim = add k get trq 1 145 while lt k lim bound `9223372036854775807` 146 if space mg k 147 k = add k 1 148 continue 149 end 150 s = k 151 while lt k lim bound `9223372036854775807` 152 if space mg k 153 break 154 end 155 k = add k 1 156 end 157 n = sub k s 158 if or mist s n trbrand mist s n trmono 159 ret true 160 end 161 if or mist s n trdigest mist s n trfiles 162 ret true 163 end 164 end 165 ret false 166 end 167 168 fn trmust a ulong n ulong e ulong to bool 169 z = sub n a 170 if or mist a z trcode mist a z trpre 171 ret true 172 end 173 if or mist a z trkbd mist a z trsamp 174 ret true 175 end 176 ret trclasses n e 177 end 178 179 fn trvoid a ulong n ulong e ulong to bool 180 if eq mg sub e 2 47 181 ret true 182 end 183 z = sub n a 184 if or mist a z vtmeta mist a z vtlink 185 ret true 186 end 187 if or mist a z vtbr mist a z vtimg 188 ret true 189 end 190 if or mist a z vthr mist a z vtwbr 191 ret true 192 end 193 ret or mist a z vtinput or mist a z vtsource mist a z vtcol 194 end 195 196 fn trwc c uchar to bool 197 ret or alnum c or eq c 95 or eq c 45 or eq c 46 or eq c 47 or eq c 64 eq c 58 198 end 199 200 fn trtoken a ulong e ulong to bool 201 note Protect a hex run of 7+ (upper or lower), identifier prefixes, and path/file-like words. 202 k = a 203 hxrun = ulong 0 204 digit = false 205 dot = false 206 while lt k e bound `9223372036854775807` 207 c = mg k 208 if lt hexv c 16 209 hxrun = add hxrun 1 210 if and ge c 48 le c 57 211 digit = true 212 end 213 if and ge hxrun 7 digit 214 ret true 215 end 216 else 217 hxrun = 0 218 digit = false 219 end 220 if or eq c 46 eq c 47 221 dot = true 222 end 223 k = add k 1 224 end 225 if dot 226 ret true 227 end 228 if or trat a e trrad trat a e trdid 229 ret true 230 end 231 if ge sub e a 29 232 if eq mg a 122 233 ret true 234 end 235 end 236 ret false 237 end 238 239 fn trword s ulong k ulong mode ulong to void 240 t = k 241 while gt t s bound `9223372036854775807` 242 c = mg sub t 1 243 if not or eq c 46 or eq c 58 or eq c 45 eq c 47 244 break 245 end 246 t = sub t 1 247 end 248 hit = false 249 if gt t s 250 hit = trtoken s t 251 end 252 if and hit eq get trq 3 0 253 if eq mode 1 254 die trerr 255 end 256 ot trspan 257 om s sub t s 258 ot trend 259 om t sub k t 260 else 261 if eq mode 0 262 om s sub k s 263 end 264 end 265 end 266 267 fn trtext a ulong e ulong mode ulong to void 268 k = a 269 while lt k e bound `9223372036854775807` 270 if not trwc mg k 271 if eq mode 0 272 ob mg k 273 end 274 k = add k 1 275 continue 276 end 277 s = k 278 while lt k e bound `9223372036854775807` 279 if not trwc mg k 280 break 281 end 282 k = add k 1 283 end 284 trword s k mode 285 end 286 end 287 288 fn tropen a ulong n ulong e ulong mode ulong to void 289 must = and trmust a n e eq get trq 3 0 290 has = trget n e trattr 291 no = false 292 if has 293 no = mist get trq 0 get trq 1 trnov 294 if and not no or must ne get trq 3 0 295 die trerr 296 end 297 end 298 if and must not no 299 if eq mode 1 300 die trerr 301 end 302 no = true 303 end 304 if eq mode 0 305 om sub a 1 add sub n a 1 306 if and must not has 307 ot trno 308 end 309 om n sub e n 310 end 311 if trvoid a n e 312 ret 313 end 314 d = add get trq 2 1 315 put trq 2 d 316 if and no eq get trq 3 0 317 put trq 3 d 318 end 319 if and eq get trq 4 0 trget n e trlang 320 put trq 4 d 321 end 322 if mist a sub n a trtitle 323 put trq 5 d 324 end 325 end 326 327 fn trwalk a ulong e ulong mode ulong zh bool to void 328 for j ulong 6 329 put trq j 0 330 end 331 k = a 332 while lt k e bound `9223372036854775807` 333 if eq mg k 60 334 if trat k e tcmo 335 q = mfirst k e tcme 336 if eq q e 337 die ermark 338 end 339 q = add q len tcme 340 if eq mode 0 341 om k sub q k 342 end 343 k = q 344 continue 345 end 346 q = trtagend k e 347 j = add k 1 348 if eq mg j 47 349 d = get trq 2 350 if eq get trq 3 d 351 put trq 3 0 352 end 353 if eq get trq 4 d 354 put trq 4 0 355 end 356 if eq get trq 5 d 357 put trq 5 0 358 end 359 if gt d 0 360 put trq 2 sub d 1 361 end 362 if eq mode 0 363 om k sub q k 364 end 365 else 366 n = trname j q 367 if eq n j 368 if eq mode 0 369 om k sub q k 370 end 371 else 372 tropen j n q mode 373 end 374 end 375 k = q 376 else 377 s = k 378 while lt k e bound `9223372036854775807` 379 if eq mg k 60 380 break 381 end 382 k = add k 1 383 end 384 if ne get trq 5 0 385 if eq mode 0 386 om s sub k s 387 end 388 else 389 trtext s k mode 390 end 391 end 392 end 393 end 394 395 fn trcheck to void 396 note Validation is run on reread output too; a changed manifest does not bypass it. 397 mark = sg TOP 398 n = sg OBN 399 a = stash 400 trwalk a add a n 1 false 401 put st TOP mark 402 put st OBN n 403 end 404 405 fn trurl r ulong suffix view uchar * absolute bool to void 406 b = mul r 8 407 if absolute 408 zurl r 409 else 410 om rg add b 2 rg add b 3 411 end 412 ot suffix 413 end 414 415 fn trlinks r ulong to void 416 a = stash 417 e = add a sg FLEN 418 h = mfirst a e zhead 419 v = mfirst a e trhead 420 f = mlast a e zfoot 421 if or eq h e or eq v e eq f e 422 die trlayout 423 end 424 om a sub h a 425 ot tralt1 426 trurl r trtxt false 427 ot tralt3 428 ot tralt2 429 trurl r trjson false 430 ot tralt3 431 om h sub v h 432 ot trhlink 433 om v sub f v 434 ot trflink 435 trurl r trtxt false 436 ot trtextl 437 trurl r trjson false 438 ot trjsonl 439 om f sub e f 440 end 441 442 fn trpage r ulong to void 443 trlinks r 444 note Run the existing text policy and markup checks first so refused input keeps its diagnostic. 445 polscan true 446 chkmark true 447 a = stash 448 e = add a sg FLEN 449 trwalk a e 0 false 450 end 451 452 fn trjesc a ulong n ulong to void 453 for k ulong n bound `9223372036854775807` 454 c = mg add a k 455 if or eq c 34 eq c 92 456 ob 92 457 ob c 458 else 459 if lt c 32 460 ob 92 461 ob 117 462 ob 48 463 ob 48 464 ob hexc shr ulong c 4 465 ob hexc and ulong c 15 466 else 467 ob c 468 end 469 end 470 end 471 end 472 473 text trmaino "