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