static analysis for java servlets and jsp...transforming to tag-form 1. make

12
Static Analysis for Static Analysis for Java Java Servlets Servlets and JSP and JSP Christian Kirkegaard Anders Møller BRICS, University of Aarhus

Upload: others

Post on 25-Nov-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Static Analysis for Java Servlets and JSP...Transforming to tag-form 1. make

Static Analysis for Static Analysis for Java Java ServletsServlets and JSPand JSP

Christian KirkegaardAnders Møller

BRICS, University of Aarhus

Page 2: Static Analysis for Java Servlets and JSP...Transforming to tag-form 1. make

2 / 12

Java Servlets and JSPJava Servlets and JSP

A powerful framework for Web application developmentCommunication using HTTP:

JSP pages are compiled into servlets...

response (XHTML)response (XHTML)

request (URL + form fields) request (URL + form fields) serverserverclientclient

Page 3: Static Analysis for Java Servlets and JSP...Transforming to tag-form 1. make

3 / 12

The The ServletServlet APIAPI

A Web application contains a collection of servletsA configuration file maps URL requests to servlet namesEach servlet receives user input(form fields) and produces XHTML output

The output is generated by printing characters to a stream!

Page 4: Static Analysis for Java Servlets and JSP...Transforming to tag-form 1. make

4 / 12

Two challenges for Web app developersTwo challenges for Web app developers

1. Is the response always well-formed and valid?

2. Do forms and fields being generated always match the code that receives the input?

Page 5: Static Analysis for Java Servlets and JSP...Transforming to tag-form 1. make

5 / 12

Overview of the analysisOverview of the analysis

Java codeJava code

flow graphflow graph

contextcontext--free grammarfree grammar

grammar on taggrammar on tag--formform

XML graphXML graph

Soot (Hendren et al.) + string analysis (SAS’03)

balanced grammars (Knuth)+ much more...

XML Schema validation (PLAN-X’06)

Page 6: Static Analysis for Java Servlets and JSP...Transforming to tag-form 1. make

6 / 12

Our resultsOur results

Construction of context-free grammarsthat approximate the possible outputon output streams in Java

Checks for XML well-formedness and XML Schema validity on context-free grammars

Inter-servlet control flow for Web apps

Page 7: Static Analysis for Java Servlets and JSP...Transforming to tag-form 1. make

7 / 12

Flow graphsFlow graphs

Nodes:append[regular language]

invoke[possible targets]

nop

return

Edges represent control flow

– Soot (Hendren et al.) gives us Jimple code, control flow analysis, and alias analysis

– String analysis (SAS’03) gives us a regular language for each string expression

Java codeJava code

flow graphflow graph

contextcontext--free grammarfree grammar

grammar on taggrammar on tag--formform

XML graphXML graph

Page 8: Static Analysis for Java Servlets and JSP...Transforming to tag-form 1. make

8 / 12

Flow graphs Flow graphs →→ contextcontext--free grammarsfree grammarsJava codeJava code

flow graphflow graph

contextcontext--free grammarfree grammar

grammar on taggrammar on tag--formform

XML graphXML graphappend[L]append[L]

n

m

Nn → RL Nm

ninvoke[t]invoke[t]

m

Nn → Nt Nm

nopnopn

m

Nn → Nm

returnreturnn Nn → ε

Page 9: Static Analysis for Java Servlets and JSP...Transforming to tag-form 1. make

9 / 12

TagTag--formform

C → << T A >> C </</ T >> (element)C → X (text)C → C C (content sequence)A → W T == ”” V ”” (attribute)A → A A (attribute sequence)A → ε (empty attr. seq.)

– if the grammar can’t be brought on this form,its language is not well-formed XML

– on tag-form, we can easily check the remaining properties for well-formedness...

Java codeJava code

flow graphflow graph

contextcontext--free grammarfree grammar

grammar on taggrammar on tag--formform

XML graphXML graph

Page 10: Static Analysis for Java Servlets and JSP...Transforming to tag-form 1. make

10 / 12

Transforming to tagTransforming to tag--formform

1. make </ a single symbol2. obtain balanced grammar

with respect to < and </– Knuth ’67– Mohri & Nederhof ’01

3. obtain unique contexts (tag / element content / attribute value) – if possible

4. apply standard grammar transformations (inlining, expansion)...

Java codeJava code

flow graphflow graph

contextcontext--free grammarfree grammar

grammar on taggrammar on tag--formform

XML graphXML graph

Page 11: Static Analysis for Java Servlets and JSP...Transforming to tag-form 1. make

11 / 12

Checking validity with XML graphsChecking validity with XML graphs

An XML graph is like an XML tree but with• choices and loops• attribute/element names and text described

with regular string languages(so one XML graph represents a set of concrete XML trees)

Converting a context-free grammar on tag form into an XML graph is straightforwardWe have a tool for validating XML graphs relative to schemas (using XML Schema)!

Java codeJava code

flow graphflow graph

contextcontext--free grammarfree grammar

grammar on taggrammar on tag--formform

XML graphXML graph

Page 12: Static Analysis for Java Servlets and JSP...Transforming to tag-form 1. make

12 / 12

ConclusionConclusion

Construction of context-free grammarsthat approximate the possible outputon output streams in Java

Sound and complete checks for XML well-formedness and XML Schema validityon context-free grammars

Inter-servlet control flowfor Servlets/JSP Web apps

...and the implementation is on the way – reeeal soon now ☺

Java codeJava code

flow graphflow graph

contextcontext--free grammarfree grammar

grammar on taggrammar on tag--formform

XML graphXML graph